给定以下基本方案:
Category
- id
- isDeleted
Product
- id
- Category
- isDeleted
我如何过滤符号/学说查询仅显示其自己的 isDeleted
值为false 和其父类别的 isDeleted
值的产品?我目前有:
$query = $em-createQuery("SELECT p FROM AppBundle:Product p WHERE p.quantity > 0 AND p.isDeleted = FALSE AND ORDER BY p.modifiedAt DESC");
,但我不确定如何向上移动并添加诸如AND p.category.isDeleted = FALSE
之类的东西。具体来说,尝试这给我一个语法错误。
您几乎在那里,只需要使用JOIN
进行CC_4:
SELECT p FROM AppBundle:Product p JOIN p.category c WHERE p.quantity > 0
AND p.isDeleted = FALSE AND c.isDeleted = FALSE ORDER BY p.modifiedAt DESC