aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-01-03 21:24:09 +0530
committerPratik Naik <pratiknaik@gmail.com>2010-01-03 21:25:19 +0530
commit00f3f6dc3145f2d7e8b8dadd966008cd0fa54636 (patch)
tree4b0fb5d2df9e8cbefdc17abfb90e0459fff7737c /activerecord
parent3db876cb761837ebf9b02d22846353e277ff14cd (diff)
downloadrails-00f3f6dc3145f2d7e8b8dadd966008cd0fa54636.tar.gz
rails-00f3f6dc3145f2d7e8b8dadd966008cd0fa54636.tar.bz2
rails-00f3f6dc3145f2d7e8b8dadd966008cd0fa54636.zip
Relation#merge and Relation#except should respect locks
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/spawn_methods.rb4
-rw-r--r--activerecord/test/cases/relations_test.rb5
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 }