Using Laravel and Eloquent. I have a database that looks like this:
The dance_performers.dance_perfomer_type field hosts values such as '\App\Dancer', '\App\Couple' or '\App\Formation'.
How would you proceed to connect the dance_performers.dance_perfomer_id to the different models? I am not sure how I am supposed to write the relationships in the different models.
Should I create a \App\Performer model which would then direct to one of the three previously mentioned?
Using polymorphic relations:
class Dance extends Model {
public function couples() {
return $this->morphedByMany('\App\Couple', 'dance_performer');
}
}
class Couple extends Model
{
public function dances() {
return $this->morphToMany('App\Dance', 'dance_performer');
}
}
Currently, $dances = \App\Dance::with('couples')->get(); only returns empty relations.
I would appreciate the help.
