I have a Account
model with 3 attachments, using Active Storage, has_many_attached :attachments
.
I want to know how many attached files the account has, the most efficient way (aka no joins)
The only solution I found is
Account.last.attachments.count
or .size
, but it makes two query: one for the account and one using active_storage_attachments table.
Is there a way to counter cache the number of attachments?
Thank you in advance
EDIT
Of course I can set up my own database field and count it, I want to know if there is some default
EDIT
I tried to do has_many_attached :attachments, counter_cache: true
, but it gives an error