Lets say I have a project model which has many members and many tasks.
class Project < ActiveRecord::Base
has_many :memberships
has_many :members, :through => :memberships, :class_name => 'User'
has_many :tasks
end
When a task is created in the project, we keep a record of which user created it. Only users who are a member of the current project can
class Task < ActiveRecord::Base
belongs_to :creator, :class_name => 'User'
belongs_to :project
end
In my projects#show
action, I want to find a project and display it along with it's members, tasks and their creators. I try to eager load these things in order to speed up the query.
Since I am eager loading the searches members, and tasks can only have a creator who is a member, am I right in thinking that I don't have to include the task's creator specifically?
In other words, can I do this:
Search.includes(:members, :tasks)
or should I do this:
Search.includes(:members, :tasks => :creator)