Code snippets for symfony 1.x

Navigation

update according to the primary key using propel

If you want to make an update according to the primary key you just need to use one criteria:

$c = new Criteria();
 
$c->add(MyObjectPeer::ID,123);
 
$c->add(MyObjectPeer::NAME,'ola');
$c->add(MyObjectPeer::CITY,'pepito');
 
MyObjectPeer::doUpdate($c);
 

and the query is:

UPDATE my_object SET NAME = 'ola',CITY = 'pepito' WHERE my_object.ID=123
 

Compared to the update query using Propel snippet which pass 2 criterias to the BasePeer:doUpdate method, here we pass only one criteria to the MyObjectPeer::doUpdate method. This method remove the index ID of the "set" criteria and use it for the "select" criteria.

by sampq on 2007-12-05, tagged criteria  propel 

Comments on this snippet

gravatar icon
#1 Francois Zaninotto on 2007-12-13 at 10:29

Works only if your Where clause is only on the object primary key, so this solution can only be used in a limited number of cases.