Symfony 和 Doctrine 2 - 根据相关实体值过滤结果
Symfony and Doctrine 2 - filtering results based on related entity values
给定以下基本场景:
Category
- id
- isDeleted
Product
- id
- Category
- isDeleted
如何过滤 Symfony/Doctrine 查询以仅显示 isDeleted
值为 false 和 其父类别的 isDeleted
值为 false 的产品错误的?我目前有:
$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
和 category
:
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
给定以下基本场景:
Category
- id
- isDeleted
Product
- id
- Category
- isDeleted
如何过滤 Symfony/Doctrine 查询以仅显示 isDeleted
值为 false 和 其父类别的 isDeleted
值为 false 的产品错误的?我目前有:
$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
和 category
:
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