我想对关联对象使用Collection#Matching,但它不起作用。做一些挖掘它看起来像Doctrine对这两个值进行in_array调用。针是Persisted Collection(我的关联),haystack是我想要匹配的实体的数组。因为针是持久收集,匹配失败。
这可能是错误还是不支持关联?如果他们不受支持,是否有解决方法?
示例:
$query = $em->createQuery("SELECT c FROM Entity\BidCategory c WHERE c.code IN(:categories)");
$query->setParameter('categories', array('CATEGORY_1', 'CATEGORY_2'));
$my_categories = $query->getResult();
$criteria = array(
"min_pub_date" => "01-07-2012",
"max_pub_date" => "01-08-2012"
);
$query = $em->createQuery("SELECT b From Entity\Bid b JOIN b.categories c WHERE b.pub_date > :min_pub_date AND b.pub_date < :max_pub_date");
$query->setParameter("min_pub_date", new DateTime($criteria['min_pub_date']));
$query->setParameter("max_pub_date", new DateTime($criteria['max_pub_date']));
$query->setMaxResults(1);
$bids = $query->getResult();
$criteria = Criteria::create()
->where(Criteria::expr()->in("categories", $my_categories));
$collection = new Doctrine\Common\Collections\ArrayCollection();
foreach($bids as $bid)
{
$collection->add($bid);
}
$matched_bids = $collection->matching($criteria);
答案 0 :(得分:0)
标准功能不支持关联。 Criteria::expr()->in()
方法适用于常规数组。