Skip to content

Instantly share code, notes, and snippets.

@pechorin
Last active December 16, 2015 16:09
Show Gist options
  • Save pechorin/5460949 to your computer and use it in GitHub Desktop.
Save pechorin/5460949 to your computer and use it in GitHub Desktop.
rails 3.2.13 scopes auto merging :(
# Как и ожидалось:
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