开发者

Doctrine where in with Doctrine_Query

开发者 https://www.devze.com 2023-02-20 06:58 出处:网络
is it possible to make : $q->createQuery(\'q\') ->whereIn(\'q.id\', $q2) Where 开发者_如何学JAVA$q2 is an other Doctrine_Query object. Because my subquery is complex and I don\'t want to writ

is it possible to make :

$q->createQuery('q')
  ->whereIn('q.id', $q2)

Where 开发者_如何学JAVA$q2 is an other Doctrine_Query object. Because my subquery is complex and I don't want to write it in SQL...


Unfortunately, according to the Doctrine API documentation, you can't pass another query object to whereIn(), so you will have to fetch your ID-s beforehand and pass them in an array. Be careful though, because if you pass an empty array, then there will be NO FILTERING for those ID-s. In other words: it will return all rows present in your table, instead of none.


While using whereIn the parameter should be an array. You can use execute(array(), Doctrine_Core::HYDRATE_ARRAY) to return an array instead of an object.

0

精彩评论

暂无评论...
验证码 换一张
取 消