Well, thanks to @pfaffman I have identified the relevant posts using this:
Post.find_by_sql("select id from posts where topic_id not in (select id from topics)")
I get this output:
[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
However, I cannot work out how to then apply destroy_all
to this selection.
This might help (for my own benefit):
Any suggestions?