从ruby中的update all获取更改的记录

从ruby中的update all获取更改的记录,ruby,rails-activerecord,Ruby,Rails Activerecord,在postgresql中,这是有效的 update products set status = 1 where status <> 1 and updated_at < '2014-04-01' returning id; 更新产品集状态=1 其中状态1和更新位置为

在postgresql中,这是有效的

update products set status = 1 
where status <> 1 and updated_at < '2014-04-01'
returning id;
更新产品集状态=1
其中状态1和更新位置为<'2014-04-01'
返回id;
这是最方便的,因为我得到了我刚刚更新的所有记录的id

在活动记录中是否有这样做的方法?
我正在(非常努力)做一个更像红宝石的人。
我发现在这种情况下泄漏的抽象有点难

我知道update\u all会返回计数。
是否有允许返回的调用?

对于Rails 4:

Product.where('updated_at < ? and not status = ?', '2014-04-01', 1).map do |product|
  product.update_attribute(:status, 1)
  product.id
end
Product.where('updated_at<?而非status=?','2014-04-01',1)。地图do | Product|
product.update_属性(:status,1)
产品id
结束
对于Rails[“更新于”<且状态不在(?),“2014-04-01”,1])。产品地图| product.update_属性(:status,1) 产品id
其中的某些部分需要纠正-当您查找
状态=1
时,OP询问
状态1
(不等于)。此外,OP需要更新该记录,您只是在更改对象,而不是保存更改。:)
Product.where('updated_at < ? and status != ?', '2014-04-01', 1).map do |product|
product.update_attribute(:status, 1)
product.id
Product.where('updated_at < ? and status NOT IN (?)', '2014-04-01', 1).map do |product|
product.update_attribute(:status, 1)
product.id
Product.find(:all, :conditions => ['updated_at < ? and status NOT IN (?)', '2014-04-01', 1]).map do |product|
product.update_attribute(:status, 1)
product.id