Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Deprecate Relation#& alias for Relation#merge

  • Loading branch information...
commit 66003f596452aba927312c4218dfc8d408166d54 1 parent 22d1fee
@ernie ernie authored tenderlove committed
View
5 activerecord/lib/active_record/relation/spawn_methods.rb
@@ -67,7 +67,10 @@ def merge(r)
merged_relation
end
- alias :& :merge
+ def &(r)
+ ActiveSupport::Deprecation.warn "Using & to merge relations has been deprecated and will be removed in Rails 3.1. Please use the relation's merge method, instead"
+ merge(r)
+ end
def except(*skips)
result = self.class.new(@klass, table)
View
2  activerecord/test/cases/method_scoping_test.rb
@@ -229,7 +229,7 @@ def test_scoped_create
end
def test_scoped_create_with_join_and_merge
- (Comment.where(:body => "but Who's Buying?").joins(:post) & Post.where(:body => 'Peace Sells...')).with_scope do
+ Comment.where(:body => "but Who's Buying?").joins(:post).merge(Post.where(:body => 'Peace Sells...')).with_scope do
assert_equal({:body => "but Who's Buying?"}, Comment.scoped.scope_for_create)
end
end
View
18 activerecord/test/cases/relations_test.rb
@@ -536,17 +536,21 @@ def test_select_argument_error
end
def test_relation_merging
- devs = Developer.where("salary >= 80000") & Developer.limit(2) & Developer.order('id ASC').where("id < 3")
+ devs = Developer.where("salary >= 80000").merge(Developer.limit(2)).merge(Developer.order('id ASC').where("id < 3"))
assert_equal [developers(:david), developers(:jamis)], devs.to_a
- dev_with_count = Developer.limit(1) & Developer.order('id DESC') & Developer.select('developers.*')
+ dev_with_count = Developer.limit(1).merge(Developer.order('id DESC')).merge(Developer.select('developers.*'))
assert_equal [developers(:poor_jamis)], dev_with_count.to_a
end
+ def test_relation_ampersand_merge_deprecation
+ assert_deprecated { Developer.where("salary >= 80000") & Developer.limit(2) }
+ end
+
def test_relation_merging_with_eager_load
relations = []
- relations << (Post.order('comments.id DESC') & Post.eager_load(:last_comment) & Post.scoped)
- relations << (Post.eager_load(:last_comment) & Post.order('comments.id DESC') & Post.scoped)
+ relations << Post.order('comments.id DESC').merge(Post.eager_load(:last_comment)).merge(Post.scoped)
+ relations << Post.eager_load(:last_comment).merge(Post.order('comments.id DESC')).merge(Post.scoped)
relations.each do |posts|
post = posts.find { |p| p.id == 1 }
@@ -555,18 +559,18 @@ def test_relation_merging_with_eager_load
end
def test_relation_merging_with_locks
- devs = Developer.lock.where("salary >= 80000").order("id DESC") & Developer.limit(2)
+ devs = Developer.lock.where("salary >= 80000").order("id DESC").merge(Developer.limit(2))
assert_present devs.locked
end
def test_relation_merging_with_preload
- [Post.scoped & Post.preload(:author), Post.preload(:author) & Post.scoped].each do |posts|
+ [Post.scoped.merge(Post.preload(:author)), Post.preload(:author).merge(Post.scoped)].each do |posts|
assert_queries(2) { assert posts.first.author }
end
end
def test_relation_merging_with_joins
- comments = Comment.joins(:post).where(:body => 'Thank you for the welcome') & Post.where(:body => 'Such a lovely day')
+ comments = Comment.joins(:post).where(:body => 'Thank you for the welcome').merge(Post.where(:body => 'Such a lovely day'))
assert_equal 1, comments.count
end

2 comments on commit 66003f5

@codesnik

why? it couldn't hurt anyone, and looked rather nice

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