我有2张桌子。
表1:
product_prices:
id | price |description |pack |display |created |modified |
表2:
payment_infos:
id |payer |pay_date |product_price_id |product_price |
在payment_infos
模型中
$this->belongsTo('ProductPrices', [
'foreignKey' => 'product_price_id',
'className' => 'ProductPrices',
]);
我有这个问题:
$query = $this->find('all', [
'contain' => ['ProductPrices']
]));
运行上述查询时,出现以下错误:
Warning (512): Association property name "product_price" clashes
with field of same name of table "payment_infos".
You should explicitly specify the "propertyName" option.
[CORE\src\ORM\Association.php, line 722]
答案 0 :(得分:3)
propertyName :应将关联表中的数据填充到源表结果中的属性名称。默认情况下,这是强调的&在我们的示例中,关联的单数名称为product_price
。
由于product_price
中的字段名称payment_infos
会产生冲突,因此我将默认属性名称更改为自定义名称。
$this->belongsTo('ProductPrices', [
'foreignKey' => 'product_price_id',
'className' => 'ProductPrices',
'propertyName' => 'prod_price'
]);