@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 を適用する方法がわかりません。
これは(私の利益のために)役立つかもしれません。
何か提案はありますか?