This will return all posts that do not have an image. If you want to find all posts that have an image attached, you would use a #not clause in there like so:
This can even be extended to has_many_attached by using the plural form of :image_attachment like so:
classPost< ApplicationRecord
has_many_attached :imagesend# Query for all without attachmentsPost.left_joins(:image_attachments).where(active_storage_attachments:{id:nil})# Query for all with attachmentsPost.left_joins(:image_attachments).where.not(active_storage_attachments:{id:nil})
Final Syntax
The syntax for attachments is fairly straightforward like so: