我有以下型号:
Product
BaseProduct
BaseCode
Series
它们每个都是独立的实体,但它们是相关的。
Product
有一个外键BaseProduct
, BaseProduct
有一个外键BaseCode
and BaseCode
有一个外键Series
.
我已经在我的方法中指定了一个方法BaseCode
模型,这样我就可以选择所有Products
与该特定相关的BaseCode
:
public function Products()
{
return $this->hasManyThrough('Product', 'BaseProduct', 'BaseCodeId', 'BaseProductId');
}
BaseCodeId
是 PKBaseCode
和 FK 在BaseProduct
指向该 PK,并且BaseProductId
是 PKBaseProduct
,并且在Product
表中,有一个 FK 指向它。
这一切都很好,对我来说非常有用。
不过,我想更进一步,并在我的中定义类似以下内容的内容Series
model:
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');
}
我如何获得所有Product
与 相关联Series
像那样?