UNION query with Propel ORM
Asked Answered
S

2

6

I'm trying to create a UNION query using the Propel ORM e.g

$criterion1 UNION $criterion2

Does anyone know how to do this?

Sevenfold answered 31/12, 2009 at 14:34 Comment(0)
B
4

You cannot create a union query using Criteria. Instead, you can create the SQL string yourself, and use it to hydrate the objects. If you still want to use Criteria to build both parts of the union query, you can call BasePeer::createSelectSql(Criteria $criteria, array &$params). This will return an SQL string with ? in the places of the values that need to be set by the PDO layer. The second parameter is an array that will be filled with these parameters (which is why you pass it by reference). You can pass this to the PDOStatement::execute(array $params) function.

Brahmaputra answered 2/1, 2010 at 12:13 Comment(4)
@NeelBasu: The link forwarded me to the new adddress, I updated it.Brahmaputra
The link is broken again (because the wiki is broken) but the text can still be found here. The version for the current release (1.6) can be found here.Dinahdinan
Your link is also broken @Ladadadada.Curvy
The link was changed by Propel yet again, so I've updated it.Spathic
W
2

Two solutions come to mind. Firstly, the trivial approach is to run two separate calls and then use array_merge to glue them together. Depending on your use-case, this may not be as time-expensive as you think.

Also, if you are stuck writing the query, write a view with the query you want, and then put that in your Propel model. I had a bunch of very complicated master-detail screens in Propel/symfony 1.x, and this approach worked a treat. It does go slightly against the philosophy of using an ORM, but hey, it's fun to break the rules once in a while! :)

Wolcott answered 29/9, 2011 at 18:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.