9

如何从 Rake 任务向数据库服务器发送这样的查询而不删除“每个”循环中的逐条记录?

delete from data
where uuid in (
    select uuid
    from data
    group by uuid, raw, recdate
    having count(*)>1
);
4

1 回答 1

9

ActiveRecord 有delete_all适合你的方法。请注意,它不会调用销毁回调。http://api.rubyonrails.org/classes/ActiveRecord/Relation.html#method-i-delete_all

于 2012-05-15T11:57:33.293 回答