I have the following models:
Product
BaseProduct
BaseCode
Series
Each of them is something like a separate entity, but they are interconnected.
Producthas a foreign key for BaseProduct, BaseProducthas a foreign key for BaseCodeand BaseCodehas a foreign key Series.
I have specified a method in my model BaseCode, so I can select all Productsthat apply to this particular one BaseCode:
public function Products()
{
return $this->hasManyThrough('Product', 'BaseProduct', 'BaseCodeId', 'BaseProductId');
}
BaseCodeIdis PK for BaseCodeand FK in BaseProduct, which points to PK, and BaseProductIdis PK for BaseProduct, and in the table ProductFK, which points to it.
It's good and good, and for me it's just a dandy.
I would like to go one more level and define Seriessomething like the following in my model :
public function Products()
{
return $this->BaseProducts()->
}
public function BaseProducts()
{
return $this->hasManyThrough('BaseProduct', 'BaseCode', 'SeriesId', 'BaseCodeId');
}
Product, Series, ?