我有两张桌子。
表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]发布于 2017-05-31 13:30:50
propertyName:应该将关联表中的数据填充到源表结果中的属性名称。默认情况下,在我们的示例中,这是关联的强调和单数名称,所以是product_price。
由于您已经在product_price中有一个字段名payment_infos,因此它会产生冲突,因此我将默认属性名更改为自定义名称。
$this->belongsTo('ProductPrices', [
'foreignKey' => 'product_price_id',
'className' => 'ProductPrices',
'propertyName' => 'prod_price'
]);请参阅BelongsTo协会
https://stackoverflow.com/questions/44281597
复制相似问题