Rails6:查找只有ActiveText附件的记录

Rails 6: Lookup records that have only have ActiveText attachments

我有一个 User 模型有一个

has_rich_text :tlk_with_me

已附加富文本 blob。

在我的一个页面上,我想用 tlk_with_me blob 加载所有用户,并加载其他用户的 none。

我已经尝试过这个答案中的解决方案:

建议执行以下查询:

@users_with_twm_attached = User.joins(:tlk_with_me_attachment)

但是我收到以下错误:

ActiveRecord::ConfigurationError (Can't join 'User' to association named 'tlk_with_me_attachment'; perhaps you misspelled it?)

我不确定如何进行。谢谢

您的案例的关联将是 rich_text_tlk_with_me,因此

User.joins(:rich_text_tlk_with_me)

(也可能是 .where('action_text_rich_texts.body!=""') 左右)