diff options
Diffstat (limited to 'activerecord/lib/active_record/relation/spawn_methods.rb')
-rw-r--r-- | activerecord/lib/active_record/relation/spawn_methods.rb | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index d417e82548..57d66bce4b 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -50,10 +50,7 @@ module ActiveRecord # Post.order('id asc').except(:order) # discards the order condition # Post.where('id > 10').order('id asc').except(:where) # discards the where condition but keeps the order def except(*skips) - result = Relation.new(klass, table, values.except(*skips)) - result.default_scoped = default_scoped - result.extend(*extending_values) if extending_values.any? - result + relation_with values.except(*skips) end # Removes any condition from the query other than the one(s) specified in +onlies+. @@ -61,11 +58,18 @@ module ActiveRecord # Post.order('id asc').only(:where) # discards the order condition # Post.order('id asc').only(:where, :order) # uses the specified order def only(*onlies) - result = Relation.new(klass, table, values.slice(*onlies)) - result.default_scoped = default_scoped - result.extend(*extending_values) if extending_values.any? - result + if onlies.any? { |o| o == :where } + onlies << :bind + end + relation_with values.slice(*onlies) end + private + + def relation_with(values) # :nodoc: + result = Relation.create(klass, table, values) + result.extend(*extending_values) if extending_values.any? + result + end end end |