Last active
December 16, 2015 16:09
-
-
Save pechorin/5460949 to your computer and use it in GitHub Desktop.
rails 3.2.13 scopes auto merging :(
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Как и ожидалось: | |
irb(main):151:0> User.where(:id => [1,2]).where(:id => [3,4]).to_sql | |
=> "SELECT \"users\".* FROM \"users\" WHERE \"users\".\"id\" IN (1, 2) AND \"users\".\"id\" IN (3, 4)" | |
# Теперь определяем скоуп: | |
irb(main):148:0> User.instance_eval { scope :with_ids, ->(ids) { where(:id => ids) } } | |
# И имеем полнешую хуйню: | |
irb(main):150:0> User.with_ids([1,2]).with_ids([3,4]).to_sql | |
=> "SELECT \"users\".* FROM \"users\" WHERE \"users\".\"id\" IN (3, 4)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment