I got 3 models, Article, Building, Person.
These models need to reference each other in a few ways. For example the building needs to be able to reference collections of Person like $building->architects(), $building->owners(), a article might reference collections of Person with $article->authors() and Person might reference collections of Building like $person->owned_buildings()
Each model should have a function like "references" to get a collection of mixed models.
I'm thinking that this should be possible with something like:
class Article extends Eloquent {
public function referenceable()
{
return $this->morphTo();
}
public function authors()
{
return $this->morphMany('Person', 'referenceable');
}
}
class Building extends Eloquent {
public function referenceable()
{
return $this->morphTo();
}
public function architects()
{
return $this->morphMany('Person', 'referenceable');
}
}
class Person extends Eloquent {
public function referenceable()
{
return $this->morphTo();
}
public function owned_buildings()
{
return $this->morphMany('Building', 'referenceable');
}
}
So the question is what would the pivot table look like?