2
一个分支可能有许多客户,客户可能与许多分支有关。所以这是一个多对多的关系。在原则中使用SQL IN语句过滤器查询
科:
<many-to-many target-entity="Customer" inversed-by="branches" field="customers"/>
客户:
<many-to-many field="branches" target-entity="Branch" mapped-by="customers"/>
现在我想下面的查询来执行:选择客户的分支定分支对象匹配的所有客户。
这是我的尝试:
$branch = $em->getRepository('MyBundle:Branch')
->findOneById($bid);
$qb->select(array('c'))
->from('MyBundle:Customer', 'c')
->where($qb->expr()->in('c.branches', $branch))
->andWhere('c.delted = 0')
->getQuery();
所以我的想法是,在语句中使用。但这不起作用。
错误:
Fatal error: Object of class DateTime could not be converted to string ..Query\Expr\Func.php on line 48
任何想法如何做到这一点的正确方法?
你应该能够做到这一点,只是用实体:$科顺> GetCustomers的();和主义会关心其余的。 (除非你想添加一些额外的条件?)或者我错过了什么? – Cyprian
我知道,但我将查询传递给一个分页器,该分页器期望一个查询而不是一组对象 –