Findbyattributes() + Cdbexpression() ?

Hi guys!

It is possible to use CDbExpression() on findByAttributes()? Im trying to use the following example:




$result = User::model()->findByAttributes(

                         array('reset_key' => $user->reset_key), 

                         'reset_expires<=:current_date', 

                                          array(':current_date' => new CDbExpression('NOW()')));



But doing this i get the query:




SELECT * FROM `tbl_user` `t` WHERE `t`.`reset_key`='xyz' AND (reset_expires<=:current_date) LIMIT 1



and ofc, its not working. The query that im trying to do is:




SELECT * FROM `tbl_user` `t` WHERE `t`.`reset_key`='xyz' AND (reset_expires<=NOW()) LIMIT 1



Any idea?

Why not simply


$result = User::model()->findByAttributes(

                         array('reset_key' => $user->reset_key), 

                         'reset_expires <= NOW()'

          );

Do something like this


     $criteria = new CDbCriteria;

          $criteria->addCondition("current_date<=".now());

          $result = User::model()->findByAttributes(array('reset_key' =>$user->reset_key),$criteria);



validate the format to print now, i am no sure to this.

I had already tested that option and it works, but doing that way, the value of reset_expires is not bound.




SELECT * FROM `tbl_user` `t` WHERE `t`.`reset_key`=:yp0 AND (reset_expires<=NOW()) LIMIT 1. Bound with :yp0='xyz'



So my question is, if I give a value to a variable that does not come from user input (eg, status=1, reset_expires<=NOW(), etc…) to be used in a query like the example above, do I need to worry about the bound values on query or is ok?

No need to worry in that case imho

Ok bennouna, ty for the info! :)