我有用户模型,其描述为富文本
has_rich_text :description
我想运行查询来检查哪些用户有描述?
类似这样的事情
User.where.not(description: nil)
我的问题:
before_save
上更新,然后运行查询 where has_description true
Rails 自动添加
has_one
关联 rich_text_#{name}
:
您可以使用它来连接(或预加载)表并过滤掉内部操作文本表:
User.joins(:rich_text_description)
.where("action_text_rich_texts.body IS NOT NULL")