# Object has two collections of objects of the same type

**URL:** <https://www.ruby-forum.com/t/object-has-two-collections-of-objects-of-the-same-type/186089>\
**Category:** Rails\
**Created:** [March 31, 2010, 1:11pm UTC](https://www.ruby-forum.com/t/object-has-two-collections-of-objects-of-the-same-type/186089 "2010-03-31T13:11:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ESESES](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f0a364/32.png) [@ESESES](https://www.ruby-forum.com/u/ESESES)\
**Post date:** [March 31, 2010, 1:11pm UTC](https://www.ruby-forum.com/t/object-has-two-collections-of-objects-of-the-same-type/186089/1 "2010-03-31T13:11:13Z")

</div>

I want to have my object class have both a collection of doc objects  
called “reports” and one called “docs”. How do I specify two  
different arrays of the same type of object?

I have this in my new method

```
@echantillon.docs.build

```

how do I do the same thing for a collection called reports of the doc  
type also?

---

<div class="post-metadata">

**Author:** ![ESESES](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/f0a364/32.png) [@ESESES](https://www.ruby-forum.com/u/ESESES)\
**Post date:** [March 31, 2010, 1:34pm UTC](https://www.ruby-forum.com/t/object-has-two-collections-of-objects-of-the-same-type/186089/2 "2010-03-31T13:34:37Z")

</div>

On 31 March 2010 12:09, ES [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I want to have my object class have both a collection of doc objects  
> called “reports” and one called “docs”. How do I specify two  
> different arrays of the same type of object?

class Whatever \< ActiveRecord.Base  
has\_many :docs  
has\_many :reports, class\_name =\> “Doc”, foreign\_key =\> “something\_id”

whatever\_id is a field in docs

class Doc \< ActiveRecord::Base  
belongs\_to :whatever  
belongs\_to :something, class\_name =\> Whatever

Then you can say whatever.docs, whatever.reports and doc.whatever and  
doc.something

> I have this in my new method
> 
> @echantillon.docs.build
> 
> how do I do the same thing for a collection called reports of the doc  
> type also?

@echantillon.reports.build

I think.

Colin
