我有以下型号:是否有可能具有比两个层次更深的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的?
谢谢你,先生。经过一番沉重的挖掘和混乱之后,我一直无法让雄辩的弯曲我喜欢的方式,并得出了相同的结论。 –