我想对关联的对象使用Collection#Matching,但它不起作用。深入研究一下,它看起来像是Doctrine对这两个值进行了in_array调用。指针是一个持久化集合(我的关联),而草堆是我想要匹配的实体的数组。因为指针是持久化集合,所以匹配失败。
这可能是一个bug,还是不支持关联?如果它们不受支持,有没有解决办法?
示例:
$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);发布于 2013-12-24 08:20:39
条件功能不支持关联。Criteria::expr()->in()方法适用于正则数组。
https://stackoverflow.com/questions/14294361
复制相似问题