开发者

Updating all records in single transaction

Right now I开发者_如何学C am using Rails AR methods to update a bunch of attributes in a table.

RaceWeek.current_week.each { |r| r.update_attributes(:games_won => 0, :games_lost => 0) }

I'd prefer to do this more efficiently in a single transaction. How can this be done?


Use update_all:

<model/association>.update_all("games_won = 0, games_lost = 0" )

Ps. Use some form of the above, because I do not know what the relation of RaceWeek to current_week is.

Also see some examples

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜