![](/img/trans.png)
[英]how to get the where clause in string format using CakePHP3 ORM?
[英]Cakephp3, How to use where clause and inner join in cakephp3?
我正试图从产品表中获取评论表。 我添加了列名'delete_yn',这意味着删除了评论。 我在下面使用了一些蛋糕查询
return $this->Product->find()
->contain(['ProductReview', 'Users'])
->where(['Product.product_code' => $productCode])
->toArray();
结果很好。
但是,现在我想检查用户是否删除了评论,并在“del_yn”列中仅显示“n”我添加了此查询
->andWhere(['Product.ProductReview.del_yn' => 'n'])
在where子句之后。
但它不起作用。
请帮忙。
而不是使用andWhere(['Product.ProductReview.del_yn' => 'n'])
,使用matching
(如果cakephp 3.0.x)或innerJoinWith()
if(cakephp 3.1.x)并过滤匹配特定关联数据的记录。 例如,
return $this->Product->find()
->matching('ProductReview', function ($q) {
return $q->where(['ProductReview.del_yn' => 'n']);
})
->contain(['ProductReview', 'Users'])
->where(['Product.product_code' => $productCode])
->group('Product.id')
->toArray();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.