Skip to content

Instantly share code, notes, and snippets.

@mataki
Created October 18, 2010 12:00
Show Gist options
  • Save mataki/632095 to your computer and use it in GitHub Desktop.
Save mataki/632095 to your computer and use it in GitHub Desktop.
# Group -has_many-> Participation
# Group.joined ==> defined named_scope
# Group.user_id_not_null ==> genarated named_scope by searchlogic
g = Group.find(1)
# SQL) SELECT * FROM `groups` WHERE (`groups`.`id` = 1)
g.participations
# SQL) SELECT * FROM `participations` WHERE (`participations`.group_id = 1)
g.participations.joined.user_id_not_null
# Acctual SQL) SELECT * FROM `participations` WHERE ((participations.user_id IS NOT NULL) AND (participations.status = 'ACTIVE'))
# Collect SQL) SELECT * FROM `participations` WHERE ((participations.user_id IS NOT NULL) AND ((participations.status = 'ACTIVE') AND (`participations`.group_id = 1)))
g.participations.joined.user_id_not_null # Redo
# SQL) SELECT * FROM `participations` WHERE (`participations`.group_id = 1) AND ((participations.user_id IS NOT NULL) AND (participations.status = 'ACTIVE'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment