![]() |
|
Snippets |
|
Imagine that you have a table with the following columns:
MyTable ------- id col1 col2
If you want to retrieve the records having col1 greater than col2, the following doesn't work:
$c = new Criteria(); $c->add(MyTablePeer::COL1, MyTablePeer::COL2, Criteria::GREATER_THAN);
Instead, you need to add a custom condition to your Criteria:
$c = new Criteria(); $c->add(MyTablePeer::COL1, MyTablePeer::COL1.'>='.MyTablePeer::COL2, Criteria::CUSTOM);
Comments on this snippet
great but it seems like the 1st parameter is not important at all, so why not replace it by null or another variable meaning "I'm not important"
{{{ $c->add(MyTablePeer::COL1, MyTablePeer::COL1.'>='.MyTablePeer::COL2, Criteria::CUSTOM); }}}
by
{{{ $c->add(null, MyTablePeer::COL1.'>='.MyTablePeer::COL2, Criteria::CUSTOM); }}}
or
{{{ $c->add(BasePeer::NULL, MyTablePeer::COL1.'>='.MyTablePeer::COL2, Criteria::CUSTOM); }}}
The 1st parameter is indeed used by Propel when stripping down the criteria for the count request. In an application, I have the following code, which works correctly. $c->add(MyTablePeer::TAGS, 'MATCH('.MyTablePeer::TAGS .') AGAINST (\''.$tags.'\' IN BOOLEAN MODE)', Criteria::CUSTOM);
As soon as I replace the 1st parameter by something else, Propel fails to create a correct count request.