aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG.md6
-rw-r--r--activerecord/lib/active_record/persistence.rb1
-rw-r--r--activerecord/test/cases/persistence_test.rb12
3 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 462c7ae115..5646c1a0f2 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,9 @@
+* After a successful `reload`, `new_record?` is always false.
+
+ Fixes #12101.
+
+ *Matthew Draper*
+
* PostgreSQL renaming table doesn't attempt to rename non existent sequences.
*Abdelkader Boudih*
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index ee634d7bb3..96e44c2f59 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -396,6 +396,7 @@ module ActiveRecord
end
@attributes = fresh_object.instance_variable_get('@attributes')
+ @new_record = false
self
end
diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb
index 1192ecd6b4..9b762fc0d5 100644
--- a/activerecord/test/cases/persistence_test.rb
+++ b/activerecord/test/cases/persistence_test.rb
@@ -865,4 +865,16 @@ class PersistenceTest < ActiveRecord::TestCase
assert_equal 1, post[:wibble]
assert_nil post.reload[:wibble]
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