我有这3张桌子
产品
product_attributes
product_attribute_values
我创建了3个模型,Product,ProductAttribute和ProductAttributeValue
产品型号
public function attributes(){
return $this->hasMany('App\ProductAttribute', 'product_type_id', 'product_type_id');
}
产品属性模型
public function attributeValues(){
return $this->hasMany('App\ProductAttributeValue', 'attribute_id', 'id');
}
然后当我试图获得具有所有相关属性和属性值的产品时
$product = Product::find(1)->with('attributes.attributeValues')->get()->toArray();
正在提取该属性的所有属性值。
问题是我不确定如何为两个不同的型号提供2个外键......
我希望我解释得很好。
答案 0 :(得分:0)
>>> from statistics import mode
>>> mode('Hello I like pie because they are like so good'.split())
'like'