# Aggregation: use composed\_of with multiple classes (tables)

**URL:** <https://www.ruby-forum.com/t/aggregation-use-composed-of-with-multiple-classes-tables/178683>\
**Category:** Rails\
**Created:** [November 9, 2009, 3:41pm UTC](https://www.ruby-forum.com/t/aggregation-use-composed-of-with-multiple-classes-tables/178683 "2009-11-09T15:41:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Demetrius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f08c70/32.png) [@Demetrius](https://www.ruby-forum.com/u/Demetrius)\
**Post date:** [November 9, 2009, 3:41pm UTC](https://www.ruby-forum.com/t/aggregation-use-composed-of-with-multiple-classes-tables/178683/1 "2009-11-09T15:41:14Z")

</div>

Does anyone know how to use composed\_of to pull data from multiple  
classes (tables)? I know how to use composed\_of to aggregate columns  
within the same table but am running in to trouble pulling from two  
tables.

The example below works but I don’t want to see standard.strand\_id, I  
want to see strand.name (which is in the Strand table, not the  
Standard table).

class Standard \< ActiveRecord::Base  
composed\_of :full\_standard,  
:mapping =\>  
[  
%w[grade grade],  
%w[strand\_id strand\_id]  
%w[number number]  
]

class FullStandard \< ActiveRecord::Base  
attr\_reader :grade, :strand\_id, :number

def initialize(grade, strand, number)  
@grade = grade  
@strand\_id = strand\_id  
@number = number  
end

def to\_s  
[@grade, @strand\_id, @number].compact.join(" ")  
end  
end

Again, this works, BUT I don’t want to see the strand\_id, I want to  
see strand.name (a column in the Strand table–not the Standard table)

Also, here are the table relationships:

class Standard  
belongs\_to :strand

class Strand  
has\_many :standards

Thank you!!!

---

<div class="post-metadata">

**Author:** ![Demetrius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f08c70/32.png) [@Demetrius](https://www.ruby-forum.com/u/Demetrius)\
**Post date:** [November 12, 2009, 2:01pm UTC](https://www.ruby-forum.com/t/aggregation-use-composed-of-with-multiple-classes-tables/178683/2 "2009-11-12T14:01:24Z")

</div>

Is anyone able to share some insight regarding composed\_of pulling  
from two tables?
