这里是我的产品型号:Cakephp3查询模型
$this->table('products');
$this->belongsTo('OrderProducts', [
'foreignKey' => 'order_product_id',
'propertyName' => 'order_product',
'joinType' => 'INNER'
]);
$this->hasMany('RefundProducts', [
'foreignKey' => 'product_id',
'sort' => ['RefundProducts.created' => 'DESC'],
'propertyName' => 'refund_products',
'className' => 'RefundProducts'
]);
我的查询:
$result = $this->Products->find('all', [
'contain' => [
'RefundProducts' => [
'PriceUnits',
'conditions' => $refund_condition,
]
]
]);
,但它让所有的产品, 我想唯一的产品有RefundProducts
从 选择 PRODUCT_TYPE,refund_price_unit_id,总和(refund_price) (选择 refund_price_unit_id refund_price_unit_id, (选择 product_type_id 从 产品 其中 ID = a.product_id)PRODUCT_TYPE, refund_price 从 refund_products A)B 按产品类型划分,refund_price_unit_id; 我不知道如何查询CakePHP模型查询 –
@Cao首先,请阅读本指南:** [Query Builder](http://book.cakephp.org/3.0/en/orm/query-builder的.html)**。你可以找到你需要创建的一切,并进一步定制你的查询。 之后,如果您仍然遇到问题以使您的查询正常工作,您可以针对您的特定问题发布另一个问题。 –