开发者

rails active record persistance problem

I have an orders object with a status field. I would like to retrieve all orders with status=1 (so I know what is being modified) and then update them to have a status=2. My code is as follows:

@new_orders=Order.where("status=1")

Order.where("status=1").update_all :status=>2

The problem is that @new_orders is not set until the view uses the variable. I am guessing this has to do with lazy load开发者_JAVA技巧ing. How do I get around this so I can display all records that have been modified?


Try adding .all or .to_a to the end of your relation:

@new_orders = Order.where(:status => 1).all
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜