Skip to content

Commit c1e77b2

Browse files
committed
Merge pull request #122 from orlando/od/add-n+1-queries-info
adding how to prevent n+1 queries to the README
2 parents aafd0fd + 1999868 commit c1e77b2

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,20 @@ If you don't want fancy JS features, all you have to do is just switch to `:inpu
157157
<%= f.input :images, as: :file, input_html: { multiple: true } %>
158158
```
159159

160+
### Preventing n+1 queries when loading attachinary associations
161+
162+
You can eager load attachinary associations.
163+
164+
For example, I have a `user` model that has `photo` and `avatar` as attachments.
165+
166+
```rb
167+
# user.rb
168+
has_attachment :avatar
169+
has_attachments :photos
170+
171+
# users_controller.rb
172+
User.includes(:avatar_files, :photo_files).all
173+
```
160174

161175
## Conventions
162176

0 commit comments

Comments
 (0)