Multiple Relationships in Laravel Query Builder -


i have event model , method called getevents() gets list of events events table in database.

each event in turn have delegates associated it, , becomes complicated.

there 3 tables, delegate_event (this pivot table, links delegates event based on event_id , delegate_id), delegates (a simple table containing id field , contact_id field) , contacts table contains information on list of contacts.

the delegates table uses contact_id link contacts table , pull through various pieces of information associated contact.

i using query builder , leftjoin method of information need each event need pull through list of delegates. http://paste.laravel.com/qsa

i can't work out how join contacts associated delegates associated event via delegate_event table.

can me out here please. thanks.

you need many-to-many table event-user because multiple events have multiple users (delegates) associated it.

here's have:

mtm_event_user: id, event, user

events: id, name (of event)

users: id, contact

contacts: id, name, address, etc

here's query have, can modify select suit fields need.

select * contacts inner join users on users.contact = contacts.id inner join mtm_event_user meu on meu.user = users.id meu.`event` = 1 

for multiple events, replace meu.event = 1 order meu.event


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -