rails 3: using ID from many-to-many table to do another query -
i have table contacts, table events, , joining table contact_id , event_id map many-to-many relationship.
i'm new ror , i'm used querying first table, building set of ids , running query on second table id in setofids. how done in ror well?
here's have far:
def view @contact = contact.find(params[:contact_id]) @contactevents = contacts_event.where(:contact_id => params[:contact_id]) s1 = set.new @contactevents.each |contactevent| s1.add(contactevent.event_id) end @contactevents_test = event.where(:id => @s1) end
well 1 way looking @ has_and_belongs_to_many
association (guide here). idea when @contact = contact.find(params[:contact_id])
automatically pull of associated contacts_events
1 query.
Comments
Post a Comment