Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@plainprogrammer
Created December 4, 2015 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plainprogrammer/d81591bde7d4463734cd to your computer and use it in GitHub Desktop.
Save plainprogrammer/d81591bde7d4463734cd to your computer and use it in GitHub Desktop.
current_user = User.where(full_name: "Jane Fonda").first
current_user.connections.where("full_name LIKE ?", "%bus%").select(:id, :full_name)
#
# User Load (0.6ms)
# SELECT `users`.`id`, `users`.`full_name` FROM `users`
# INNER JOIN `contacts` ON `users`.`id` = `contacts`.`connection_id`
# WHERE `contacts`.`user_id` = 980204181
# AND (full_name LIKE '%bus%')
#
# => #<ActiveRecord::AssociationRelation [
# #<User id: 550816050, full_name: "all business admin">,
# #<User id: 796115996, full_name: "all business member">
# ]>
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment