![]() |
|
Snippets |
|
Say you look for the objects of class Foo being created between $from_date and $to_date. This should do the trick:
$c = new Criteria(); $criterion = $c->getNewCriterion(FooPeer::CREATED_AT , date('Y-m-d', $from_date), Criteria::GREATER_EQUAL ); $criterion->addAnd($c->getNewCriterion(FooPeer::CREATED_AT , date('Y-m-d', $to_date), Criteria::LESS_EQUAL )); $c->add($criterion); $shows = FooPeer::doSelect($c);
Comments on this snippet
Can't you just write in a much simpler way:
or am i missing something?
->addAnd()only accepts aCriterionobject, so your solution doesn't work.And i thought dumbly that you could simply put
but now i found the case in my app i understand the point. Propel will override Criteria dor DATE by the second one, creating a request like this:
And by seeing Criteria's request storage it becomes logic that it can't have two keys for same table/column.
Now using Criterions we get:
+1 Francois :p
(btw, couln't it be possible to enlarge a bit the comment edit box??? double would be way better :p)
You are wrong, François: addAnd accepts either a Criterion object or creates one on the fly with the syntax i used.
I concur - andAnd creates a fresh Criterion object and combines it with the AND clause.
Maybe it is just me, but I have to use complete datetime format, i.e. date('Y-m-d H:i:s'). Otherwise, the query returns no match.