JoshuaESummers
JoshuaESummers

Reputation: 503

Rails 6: Lookup records that have only have ActiveText attachments

I have a User model that has a

has_rich_text :tlk_with_me

rich text blob attached.

On one of my pages I want to load all the users with a tlk_with_me blob, and none of the other users.

I have tried the solution in this answer:

How to query records that have an ActiveStorage attachment?

Which suggests doing the following query:

@users_with_twm_attached = User.joins(:tlk_with_me_attachment)

However I get the following error:

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

I am unsure how to proceed. Thank you

Upvotes: 0

Views: 256

Answers (1)

Vasfed
Vasfed

Reputation: 18444

Association for your case will be rich_text_tlk_with_me, thus

User.joins(:rich_text_tlk_with_me)

(and also probably .where('action_text_rich_texts.body!=""') or so)

Upvotes: 3

Related Questions