Update all matching records

I’m wanting to use an Ajax call to run a controller action which is to update all matching records in the db and having a complete brain freeze.

Normally, I do something like

$model = ClientsPriceList::findOne($id)

and then work with the model.

This time however, I want to find All the models/records that match a criteria

->where(['itemId' => $id])

and update the UnitPrice field for all matching records.

Can anyone offer some guidance.

I think I may have figured it out using updateAll. :grinning:

1 Like

updateAll is indeed the solution. So simple, once you know.

Great, going through documentation and api always saves time.

I try, but I still have certain trouble following some of the documentation at times, or knowing what I’m actually looking for. Once you know the proper term, then it is easy to find, but the first time you do something you can turn in circles. This is why this forum is sooooo helpful.

As always, a great big thank you!

1 Like