Я не могу найти TopicCustomField прямо сейчас (но я же сказал вам, где искать! :wink)
Вот что у нас есть:
[4] pry(main)> CategoryCustomField.last
=> #<CategoryCustomField:0x000055be74a00bd0
id: 2,
category_id: 8,
name: "enable_accepted_answers",
value: "true",
created_at: Mon, 26 Apr 2021 15:45:07.862617000 UTC +00:00,
updated_at: Mon, 26 Apr 2021 15:45:07.862617000 UTC +00:00>
Так что примерно так:
tcf=TopicCustomField.where(name: 'fun_level', value: 'super-duper-fun')
Затем вы можете получить topic_id и прочее из tcf (это массив всех совпадений). Если вы знаете topic_id, вы можете выполнить TopicCustomField.find_by(<all three things to make it unique>).