Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #16049 from matthewd/find-via-reload
After find-via-reload, the record is not new

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/persistence.rb
	activerecord/test/cases/persistence_test.rb
  • Loading branch information
matthewd committed Jul 4, 2014
1 parent 9bcf0f0 commit 3e88b9e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions activerecord/CHANGELOG.md
@@ -1,3 +1,9 @@
* After a successful `reload`, `new_record?` is always false.

Fixes #12101.

*Matthew Draper*

* `has_many :through` associations will no longer save the through record
twice when added in an `after_create` callback defined before the
associations.
Expand Down
1 change: 1 addition & 0 deletions activerecord/lib/active_record/persistence.rb
Expand Up @@ -399,6 +399,7 @@ def reload(options = nil)
@column_types = self.class.column_types
@column_types_override = fresh_object.instance_variable_get('@column_types_override')
@attributes_cache = {}
@new_record = false
self
end

Expand Down
12 changes: 12 additions & 0 deletions activerecord/test/cases/persistence_test.rb
Expand Up @@ -846,4 +846,16 @@ def test_instantiate_creates_a_new_instance
post.body
end
end

def test_find_via_reload
post = Post.new

assert post.new_record?

post.id = 1
post.reload

assert_equal "Welcome to the weblog", post.title
assert_not post.new_record?
end
end

0 comments on commit 3e88b9e

Please sign in to comment.