diff options
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation/spawn_methods.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 5 |
2 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index ea58812faa..a637e97155 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -24,7 +24,8 @@ module ActiveRecord offset(arel.skipped). select(arel.send(:select_clauses)). from(arel.sources). - having(arel.havings) + having(arel.havings). + lock(arel.locked) end relation_order = r.send(:order_clause) @@ -65,6 +66,7 @@ module ActiveRecord result = result.order(order_clause) unless skips.include?(:order) result = result.where(*@relation.wheres) unless skips.include?(:where) result = result.having(*@relation.havings) unless skips.include?(:having) + result = result.lock(@relation.locked) unless skips.include?(:lock) result end diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index bcecf74737..f895f8b8d2 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -407,6 +407,11 @@ class RelationTest < ActiveRecord::TestCase end end + def test_relation_merging_with_locks + devs = Developer.lock.where("salary >= 80000").order("id DESC") & Developer.limit(2) + assert devs.locked.present? + end + def test_relation_merging_with_preload [Post.scoped & Post.preload(:author), Post.preload(:author) & Post.scoped].each do |posts| assert_queries(2) { assert posts.first.author } |