Has many... more

Hello there,

a Person has_many projects, and a Project has_many tasks.
Thus, a Person also has many tasks.

Is there a way to write this has_many in the Person class without using
:finder_sql?

Thanks a bunch in advance!
Giuseppe

On Tue, Jun 17, 2008 at 2:54 AM, Giuseppe B. <
[email protected]> wrote:

Hello there,

a Person has_many projects, and a Project has_many tasks.
Thus, a Person also has many tasks.

Is there a way to write this has_many in the Person class without using
:finder_sql?

class Task < ActiveRecord::Base
belongs_to :project
end

class Project < ActiveRecord::Base
belongs_to :person
has_many :tasks
end

class Person < ActiveRecord::Base
has_many :projects
has_many :tasks, :through => :projects
end


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

DUH!
I had always thought that :through would only apply to a model that
belongs_to the other two (like a join table).

I should have tried this before going to the forum.

Thanks Rick,
Giuseppe

Rick Denatale wrote:

class Task < ActiveRecord::Base
belongs_to :project
end

class Project < ActiveRecord::Base
belongs_to :person
has_many :tasks
end

class Person < ActiveRecord::Base
has_many :projects
has_many :tasks, :through => :projects
end