Skip to content

Instantly share code, notes, and snippets.

@bsylvain
Created May 23, 2016 10:44
Show Gist options
  • Select an option

  • Save bsylvain/ec6d70e31184c43a49a03cd7570522d9 to your computer and use it in GitHub Desktop.

Select an option

Save bsylvain/ec6d70e31184c43a49a03cd7570522d9 to your computer and use it in GitHub Desktop.
the same query does not act the same depending on if it is used in scope or directly
scope :by_shop_id,->{
joins(:shop_data_for_users).where("shop_data_for_users.shop_id = ? and shop_data_for_users.specific_id= ?",2,'4').first
}
#console :
u = User.by_shop_id
u.count
#SELECT COUNT(*) FROM "users"
u = User.joins(:shop_data_for_users).where("shop_data_for_users.shop_id = ? and shop_data_for_users.specific_id= ?",2,'4').first
=>nil
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment