Skip to content
Browse files

Relation#merge and Relation#except should respect locks

  • Loading branch information...
1 parent 3db876c commit 00f3f6dc3145f2d7e8b8dadd966008cd0fa54636 @lifo lifo committed Jan 3, 2010
View
4 activerecord/lib/active_record/relation/spawn_methods.rb
@@ -24,7 +24,8 @@ def merge(r)
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 @@ def except(*skips)
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
View
5 activerecord/test/cases/relations_test.rb
@@ -407,6 +407,11 @@ def test_relation_merging_with_eager_load
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 }

0 comments on commit 00f3f6d

Please sign in to comment.
Something went wrong with that request. Please try again.