diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index dbf52431bd1..fb355aa37e1 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,9 @@ +* Add `ActiveRecord::Relation.readonly?` + + Reflects if the relation has been marked as readonly. + + *Theodor Tonum* + * Improve `ActiveRecord::Store` to raise a descriptive exception if the column is not either structured (e.g., PostgreSQL +hstore+/+json+, or MySQL +json+) or declared serializable via `ActiveRecord.store`. diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index f331c3fc104..034ebd24d21 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -1261,6 +1261,10 @@ module ActiveRecord records.blank? end + def readonly? + readonly_value + end + def values @values.dup end diff --git a/activerecord/test/cases/readonly_test.rb b/activerecord/test/cases/readonly_test.rb index cf9e0f022c6..9e310da563b 100644 --- a/activerecord/test/cases/readonly_test.rb +++ b/activerecord/test/cases/readonly_test.rb @@ -79,9 +79,11 @@ class ReadOnlyTest < ActiveRecord::TestCase def test_find_with_readonly_option Developer.all.each { |d| assert_not d.readonly? } + Developer.all.tap { |rel| assert_not rel.readonly? } Developer.readonly(false).each { |d| assert_not d.readonly? } Developer.readonly(true).each { |d| assert_predicate d, :readonly? } Developer.readonly.each { |d| assert_predicate d, :readonly? } + Developer.readonly.tap { |rel| assert_predicate rel, :readonly? } end def test_find_with_joins_option_does_not_imply_readonly