Active record check if rich text is present

116 views Asked by At

I have user model which has description as rich text

has_rich_text :description

I want to run a query to check which users have a description present?

Something like this

User.where.not(description: nil)

My question:

  • is it possible to check action text presence?
  • can create a migration on User model has_description(boolean) and update on before_save & then run query where has_description true
1

There are 1 answers

0
markets On

Rails automatically adds a has_one association rich_text_#{name}:

You can use it to join (or preload) the association and filter out the internal Action Text table:

User.joins(:rich_text_description) 
    .where("action_text_rich_texts.body IS NOT NULL")