问题
I have three criteria objects $c1, $c2, $c3
I want to return the union set of all three i.e.: ($c1 || $c2 || $c3) I have a function that expects a Criteria object, so I need to be able to return a criteria that represents the UNION of $c1, $c2 and $c3.
Does anyone know how to achieve that?
回答1:
You can do that with criterions:
<?php
$c = new Criteria();
$cton1 = $c->getNewCriterion(AuthorPeer::FIRST_NAME, "Leo");
$cton2 = $c->getNewCriterion(AuthorPeer::LAST_NAME, array("Tolstoy", "Dostoevsky", "Bakhtin"), Criteria::IN);
// combine them
$cton1->addOr($cton2);
// add to Criteria
$c->add($cton1);
来源:https://stackoverflow.com/questions/5063608/propel-orm-union-query