我有以下型號:是否有可能具有比兩個層次更深的HasManyThrough關係?
Product
BaseProduct
BaseCode
Series
他們每個人都是一個獨立的實體的東西,但他們的關係。
Product
有一個外鍵BaseProduct
,BaseProduct
有一個外鍵BaseCode
和BaseCode
有一個外鍵Series
。
我指定我BaseCode
模型中的一個方法,所以我可以選擇所有相關的特定BaseCode
的Products
的:
public function Products()
{
return $this->hasManyThrough('Product', 'BaseProduct', 'BaseCodeId', 'BaseProductId');
}
BaseCodeId
對於BaseCode
的PK和FK在BaseProduct
是指向那個PK,BaseProductId
是BaseProduct
的PK,在Product
表中有一個指向它的FK。
這一切都很好,併爲我工作只是花花公子。
我想去一個級別上的,雖然,確定像我Series
模型如下:
public function Products()
{
//It's here that I'd have no idea what to do - is there something like a three-level deep "hasManyThroughThrough" or something?
return $this->BaseProducts()-> /* and then whatever I'd do here to get the products */
}
public function BaseProducts()
{
return $this->hasManyThrough('BaseProduct', 'BaseCode', 'SeriesId', 'BaseCodeId');
}
如何獲得所有Series
一樣,相關的Product
S的?
謝謝你,先生。經過一番沉重的挖掘和混亂之後,我一直無法讓雄辯的彎曲我喜歡的方式,並得出了相同的結論。 –