I have 3 models: Conference , Session and Speaker . A conference can have many sessions, and many sessions can have many speakers.
Database structure
conferences ----------- id name sessions -------- id conference_id name session_speaker --------------- id session_id speaker_id speakers -------- id name
I need to write a method that allows me to get all the speakers for a particular conference (so that all speakers from all sessions of that particular conference).
The following illustrates what I think should work, but obviously this is not the way I cannot tie them together.
application / models / Conference.php
class Conference extends Eloquent { public function speakers() { return $this->hasMany('Session')->belongsToMany('Speaker'); } }
I have all the model-model relationships established and working correctly (Conference-Sessions, Session-Speakers), but I canβt create a bridge between the conference-speaker sessions. Does anyone know how I can achieve this without writing a large SQL join query?
I think that if the belongsToManyThrough() relationship existed, it would work, but it would not.
Thanks in advance!
source share