开发者

Is there a way to update an entire array or named_scope without using a loop in ruby on rails?

I create the following array using searchlogic named_scopes:

todos = Todo.asset_is("Email").asset_id_is(self.id)

For each value in the array, there is an attribute called original_date and current_date.

I need to make changes to those with some logic, such as:

difference = (original_date - date_entered) - self.days
original_date = date_entered + self.days
current_date = current_date - different

What I do not want to do is do an each do-loop. But I don't know if there's an alternative -- something lik开发者_运维问答e the "update" in SQL (but without needing to use SQL -- like using searchlogic)


Todo.update_all(["original_date = date_entered + %d, current_date = ... + %d", 
                 self.days, self.days], ["id in (?)", todos.map(&:id)])
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜