我有2张桌子。
Table 1:
product_prices:
id | price |description |pack |display |created |modified |
Table 2:
payment_infos:
id |payer |pay_date |product_price_id |product_price |
In the payment_infos
model
$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]
属性名称:应将关联表中的数据填充到源表结果中的属性名称。默认情况下,这是关联的带下划线的单数名称,因此product_price
在我们的例子中。
因为您已经有一个字段名称product_price
in payment_infos
它会产生冲突,我将默认属性名称更改为自定义名称。
$this->belongsTo('ProductPrices', [
'foreignKey' => 'product_price_id',
'className' => 'ProductPrices',
'propertyName' => 'prod_price'
]);
See 所属协会 https://book.cakephp.org/3.0/en/orm/associations.html#belongsto-associations
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)