# Combining Polymorphic Results from Related Records?

**URL:** <https://www.ruby-forum.com/t/combining-polymorphic-results-from-related-records/171709>\
**Category:** Rails\
**Created:** [July 8, 2009, 12:28am UTC](https://www.ruby-forum.com/t/combining-polymorphic-results-from-related-records/171709 "2009-07-08T00:28:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgiorno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mgiorno](https://www.ruby-forum.com/u/mgiorno)\
**Post date:** [July 8, 2009, 12:28am UTC](https://www.ruby-forum.com/t/combining-polymorphic-results-from-related-records/171709/1 "2009-07-08T00:28:18Z")

</div>

Hello,

I am trying to combine results on two related associations. I have some  
models set up as:

class Vendor \< ActiveRecord::Base  
has\_many :vendor\_staffs  
has\_many :vendor\_codes, :as =\> :vendor\_codable  
end

class VendorStaff \< ActiveRecord::Base  
belongs\_to :vendors  
has\_many :vendor\_codes, :as =\> :vendor\_codable  
end

class VendorCode \< ActiveRecord::Base  
belongs\_to :vendor\_codable, :polymorphic =\> true  
end

Is there a recommended way to derive this result:

all\_vendor\_codes = vendor.vendor\_codes +  
vendor.vendor\_staffs.collect.vendor\_codes
