Doctrine where in with Doctrine_Query

二次信任 提交于 2020-01-15 07:47:10

问题


is it possible to make :

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

Where $q2 is an other Doctrine_Query object. Because my subquery is complex and I don't want to write it in SQL...


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5433151/doctrine-where-in-with-doctrine-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!