批量永久删除已删除的帖子?

多亏了 @pfaffman,我使用以下方法识别了相关帖子:

Post.find_by_sql("select id from posts where topic_id not in (select id from topics)")

我得到了以下输出:

[1] pry(main)> Post.find_by_sql(“select id from posts where topic_id not in (select id from topics)”)
=> [#<Post:0x000055df30d4ee90 id: 150>,
#<Post:0x000055df2e538ff0 id: 51097>,
#<Post:0x000055df2e50ba28 id: 83>,
#<Post:0x000055df2e4ee8b0 id: 40636>,
#<Post:0x000055df2e4a92d8 id: 62562>,
#<Post:0x000055df2e4b7978 id: 13522>,
etc

但是,我不知道如何将 destroy_all 应用于此选择。

这可能有助于(对我自己而言):

有什么建议吗?

1 个赞