# ActiveRecord::Base Collections

**URL:** <https://www.ruby-forum.com/t/activerecord-base-collections/130991>\
**Category:** Rails\
**Created:** [March 5, 2008, 12:23am UTC](https://www.ruby-forum.com/t/activerecord-base-collections/130991 "2008-03-05T00:23:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![edmz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/898d66/32.png) [@edmz](https://www.ruby-forum.com/u/edmz)\
**Post date:** [March 5, 2008, 12:23am UTC](https://www.ruby-forum.com/t/activerecord-base-collections/130991/1 "2008-03-05T00:23:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![edmz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/898d66/32.png) [@edmz](https://www.ruby-forum.com/u/edmz)\
**Post date:** [March 5, 2008, 1:02am UTC](https://www.ruby-forum.com/t/activerecord-base-collections/130991/2 "2008-03-05T01:02:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![edmz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/898d66/32.png) [@edmz](https://www.ruby-forum.com/u/edmz)\
**Post date:** [March 5, 2008, 5:07am UTC](https://www.ruby-forum.com/t/activerecord-base-collections/130991/3 "2008-03-05T05:07:41Z")

</div>

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
