用于关联数据的 cakephp 3 queryBuilder
cakephp 3 queryBuilder for associative data
我有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 |
在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]
属性名称: 属性 名称,应使用来自关联 table 的数据填充到源 table 结果。默认情况下,这是关联的带下划线的单数名称,因此在我们的示例中为 product_price
。
由于您在 payment_infos
中已经有一个字段名称 product_price
它会产生冲突,我将默认的 属性 名称更改为自定义名称。
$this->belongsTo('ProductPrices', [
'foreignKey' => 'product_price_id',
'className' => 'ProductPrices',
'propertyName' => 'prod_price'
]);
我有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 |
在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]
属性名称: 属性 名称,应使用来自关联 table 的数据填充到源 table 结果。默认情况下,这是关联的带下划线的单数名称,因此在我们的示例中为 product_price
。
由于您在 payment_infos
中已经有一个字段名称 product_price
它会产生冲突,我将默认的 属性 名称更改为自定义名称。
$this->belongsTo('ProductPrices', [
'foreignKey' => 'product_price_id',
'className' => 'ProductPrices',
'propertyName' => 'prod_price'
]);