简体   繁体   中英

Using an SQL function when updating rows with Propel 2

I'm using Propel 2 and am trying to do a batch update of records. The following works as expected:

//UPDATE animal SET species='Duck';
AnimalQuery::create()->update(['Species' => 'Duck']);

However, I'm not sure what to do if I want to do something like the following:

UPDATE animal SET species=REPLACE(species, 'Mallard', 'Duck');

Is this possible using Propel?

The following query has the same outcome as the query you state would meet your needs.

AnimalQuery::create()->filterBySpecies("Mallard")->update(['Species' => 'Duck']);

It will issue the following query. UPDATE animal SET species='Duck' WHERE species='Mallard';

Does that meet your needs?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM