活动记录检查是否存在富文本

问题描述 投票:0回答:1

我有用户模型,其描述为富文本

has_rich_text :description

我想运行查询来检查哪些用户有描述?

类似这样的事情

User.where.not(description: nil)

我的问题:

  • 是否可以检查操作文本是否存在?
  • 可以在用户模型 has_description(boolean) 上创建迁移并在
    before_save
    上更新,然后运行查询
    where has_description true
ruby-on-rails activerecord
1个回答
0
投票

Rails 自动添加

has_one
关联
rich_text_#{name}
:

您可以使用它来连接(或预加载)表并过滤掉内部操作文本表:

User.joins(:rich_text_description) 
    .where("action_text_rich_texts.body IS NOT NULL")
© www.soinside.com 2019 - 2024. All rights reserved.