1

I am building an Rails 3.2.14. In this app I got two models, BackendUser and Project. A project can have many backendUsers through a polymorphic model called Assignment.

I need to fetch all the projects and at the same time the backendUsers belonging to each project. I am using the below code and it works fine. The problem is I only want to fetch three (3) backendUsers for each project. How can I do this?

@projects = Project.includes(:users)

I tried this in the view but then the eager loading is not working since every single backendUser creates it´s own query.

@projects.users.limit(3).each do |user|

I am using PostgreSQL.

halfer
  • 19,824
  • 17
  • 99
  • 186
Jonathan Clark
  • 19,726
  • 29
  • 111
  • 175

0 Answers0