In the class below I have a method which returns the value of two associations concatenated (#configured_resources), e.g. the union is done via ruby instead of via SQL. The issue is that I don't get a proxy back which messes up a subsequent call #to_xml(include: :my_concat_association). So it seems the better way is issue a SQL query with a UNION but I'd rather not write out the association SQL by hand--seems more logical to have a method something like #association_union( :assoc1, :assoc2) which would read the association SQL from the two associations I have defined and produce the appropriate union statement. Trouble is I can't figure out how to get the SQL out of the association. I've looked at the AssociationCollection and other proxies, but it isn't adding up for me.
Any pointer would be helpful.
class ApplicationInstance < ActiveRecord::Base
belongs_to :packaged_application
# Active Record Associations — Ruby on Rails Guides # http://my.safaribooksonline.com/book/web-development/ruby/9780132480345/advanced-active-record/ch09lev1sec7
has_many :application_resources
has_many :schema_resource_sets, :through => :application_resources, :source => :configurable, :source_type => 'SchemaResourceSet'
has_many :example_resources, :through => :application_resources, :source => :configurable, :source_type => 'ExampleResource'
def configured_resources # schema_resource_sets: # SELECT "schema_resource_sets".* # FROM "schema_resource_sets" # INNER JOIN "application_resources" # ON "application_resources".configurable_id = "schema_resource_sets".id # AND "application_resources".configurable_type = 'SchemaResourceSet' # WHERE (("application_resources".application_instance_id = 1))
schema_resource_sets + example_resources end
end