ActiveRecord::Base Collections

I have two entities (Department and Project) that extends
ActiveRecord::Base. The department is mapped to have many projects. When
i make a query using the find(:all) (Department.find(:all)), i get a
collection of the departments with the attributes(id, project_id) of the
database. I would like to receive in each department one entity of the
project class.

I will appreciate any help


class Department < ActiveRecord::Base
has_many :project
end

class Project < ActiveRecord::Base
end

Eduardo D. wrote:


class Department < ActiveRecord::Base
has_many :projects # <— note… your forgot to use the plural form here
end

class Project < ActiveRecord::Base
belongs_to :department # <— Did you forget to do this
end

Department.find(:all).map {|d| d.projects.blank? ? nil :
d.projects.first}

hth

ilan

Ilan B. wrote:

Eduardo D. wrote:


class Department < ActiveRecord::Base
has_many :projects # <— note… your forgot to use the plural form here
end

class Project < ActiveRecord::Base
belongs_to :department # <— Did you forget to do this
end

Department.find(:all).map {|d| d.projects.blank? ? nil :
d.projects.first}

hth

ilan

Still not work. I changed my classes and the project is not comming
inside of the department

I changed my classes to:

class Department < ActiveRecord::Base
has_one :project
end

class Project < ActiveRecord::Base
belongs_to :department
end