cakephp 3 queryBuilder用于关联数据 [英] cakephp 3 queryBuilder for associative data
本文介绍了cakephp 3 queryBuilder用于关联数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有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']
]));
运行上述查询时,出现以下错误:
When running the above query I get the following error:
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]
推荐答案
propertyName :应该用关联表中的数据填充到源表结果中的属性名称。默认情况下,这是强调的&关联的唯一名称,因此在我们的示例中为 product_price
。
propertyName: The property name that should be filled with data from the associated table into the source table results. By default this is the underscored & singular name of the association so product_price
in our example.
由于您已经在 payment_infos
product_price >会产生冲突,因此我将默认属性名称更改为自定义名称。
As you already have a field name product_price
in payment_infos
it generate a conflict, I changed the default property name to a custom name.
$this->belongsTo('ProductPrices', [
'foreignKey' => 'product_price_id',
'className' => 'ProductPrices',
'propertyName' => 'prod_price'
]);
请参见属于协会
这篇关于cakephp 3 queryBuilder用于关联数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文