[英]Cakephp3, How to use where clause and inner join in cakephp3?
I'm trying to get review tables from product table. 我正试图从产品表中获取评论表。 and I added column name 'delete_yn' which means the review is deleted or not.
我添加了列名'delete_yn',这意味着删除了评论。 I used some cake query below
我在下面使用了一些蛋糕查询
return $this->Product->find()
->contain(['ProductReview', 'Users'])
->where(['Product.product_code' => $productCode])
->toArray();
and the result is this fine. 结果很好。
However, now I want to check if the review was deleted by a user and show only 'n' in the column 'del_yn' I added this query 但是,现在我想检查用户是否删除了评论,并在“del_yn”列中仅显示“n”我添加了此查询
->andWhere(['Product.ProductReview.del_yn' => 'n'])
after where clause. 在where子句之后。
But it does not work. 但它不起作用。
Please Help. 请帮忙。
Instead of using andWhere(['Product.ProductReview.del_yn' => 'n'])
, use matching
(if cakephp 3.0.x) or innerJoinWith()
if(cakephp 3.1.x) and filter records matching specific associated data. 而不是使用
andWhere(['Product.ProductReview.del_yn' => 'n'])
,使用matching
(如果cakephp 3.0.x)或innerJoinWith()
if(cakephp 3.1.x)并过滤匹配特定关联数据的记录。 For example, 例如,
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.