{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/19719","labels_url":"https://api.github.com/repos/rails/rails/issues/19719/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/19719/comments","events_url":"https://api.github.com/repos/rails/rails/issues/19719/events","html_url":"https://github.com/rails/rails/issues/19719","id":67553198,"number":19719,"title":"Validation for presence of parent is failing if the parent is created inline with the child and if parent is invalid","user":{"login":"prasadsurase","id":562052,"avatar_url":"https://avatars.githubusercontent.com/u/562052?v=3","gravatar_id":"","url":"https://api.github.com/users/prasadsurase","html_url":"https://github.com/prasadsurase","followers_url":"https://api.github.com/users/prasadsurase/followers","following_url":"https://api.github.com/users/prasadsurase/following{/other_user}","gists_url":"https://api.github.com/users/prasadsurase/gists{/gist_id}","starred_url":"https://api.github.com/users/prasadsurase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prasadsurase/subscriptions","organizations_url":"https://api.github.com/users/prasadsurase/orgs","repos_url":"https://api.github.com/users/prasadsurase/repos","events_url":"https://api.github.com/users/prasadsurase/events{/privacy}","received_events_url":"https://api.github.com/users/prasadsurase/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-04-10T09:35:53Z","updated_at":"2015-04-10T18:22:06Z","closed_at":null,"body":"```ruby\r\nunless File.exist?('Gemfile')\r\n  File.write('Gemfile', <<-GEMFILE)\r\n   source 'https://rubygems.org'\r\n\r\n   ruby '2.2.1'\r\n\r\n   gem 'rails' , '4.2.1'\r\n   gem 'activerecord', '4.2.1'\r\n   gem 'arel'\r\n   gem 'sqlite3'\r\n   gem 'pry'\r\n  GEMFILE\r\n\r\n  system 'bundle'\r\nend\r\n\r\nrequire 'bundler'\r\nBundler.setup(:default)\r\n\r\n# Activate the gem you are reporting the issue against.\r\nrequire 'active_record'\r\nrequire 'minitest/autorun'\r\nrequire 'logger'\r\n#  \r\n# Ensure backward compatibility with Minitest 4\r\nMinitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)\r\n#   \r\n# This connection will do for database-independent bug reports.\r\nActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')\r\nActiveRecord::Base.logger = Logger.new(STDOUT)\r\n#    \r\n# turn off partial_writes\r\nActiveRecord::Base.partial_writes = false\r\n\r\nActiveRecord::Schema.define do\r\n  create_table :posts, force: true do |t|\r\n    t.string :title\r\n  end\r\n\r\n  create_table :comments, force: true do |t|\r\n    t.text :comment\r\n    t.integer :post_id\r\n  end\r\nend\r\n\r\nclass Post < ActiveRecord::Base\r\n  validates :title, presence: true\r\n  \r\n  has_many :comments\r\nend\r\n\r\nclass Comment < ActiveRecord::Base\r\n  validates :post, presence: true\r\n  \r\n  belongs_to :post\r\nend\r\n\r\nclass BugTest < Minitest::Test\r\n  def test_comment_is_invalid_if_post_is_not_specified\r\n    comment = Comment.create()\r\n    assert_same comment.valid?, false\r\n  end\r\n\r\n  def test_comment_is_invalid_if_invalid_post_is_specified\r\n    comment = Comment.create(comment: 'some random comment', post: Post.create())\r\n    assert_same comment.valid?, false\r\n    assert_same comment.post, Post.last\r\n  end\r\nend\r\n```\r\nHere, the comment is created with post_id as 'nil'. This is unexpected and maybe a bug."},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/91644228","html_url":"https://github.com/rails/rails/issues/19719#issuecomment-91644228","issue_url":"https://api.github.com/repos/rails/rails/issues/19719","id":91644228,"user":{"login":"meinac","id":1840945,"avatar_url":"https://avatars.githubusercontent.com/u/1840945?v=3","gravatar_id":"","url":"https://api.github.com/users/meinac","html_url":"https://github.com/meinac","followers_url":"https://api.github.com/users/meinac/followers","following_url":"https://api.github.com/users/meinac/following{/other_user}","gists_url":"https://api.github.com/users/meinac/gists{/gist_id}","starred_url":"https://api.github.com/users/meinac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meinac/subscriptions","organizations_url":"https://api.github.com/users/meinac/orgs","repos_url":"https://api.github.com/users/meinac/repos","events_url":"https://api.github.com/users/meinac/events{/privacy}","received_events_url":"https://api.github.com/users/meinac/received_events","type":"User","site_admin":false},"created_at":"2015-04-10T18:22:06Z","updated_at":"2015-04-10T18:22:06Z","body":"I think it's not a bug. If you say ```validates_presence_of :post ```\r\n this will look the comment object, post was assigned or not. \r\nIf you inspect your comment model before the assertion in second test you can see that post object assigned to the comment object(but not persistent one).\r\nAs @palkan said it can be a feature to check the persistence of the model."}}