associations support in ActiveResource?

Hello Rails Fans,
I'm working with a rails application that makes ActiveResource calls
to another rails application. Are there plans for supporting
associations between models in ActiveResource?

The following is an example of code that runs into the current limit of ARes.

on the server app there is
class CatalogEntry < ActiveRecord::Base
  belongs_to :user
  belongs_to :resource, :polymorphic => true

on the client app there is
class CatalogEntry < ActiveResource::Base = "http://localhost:3000/"

from the server rails_root i run script/console


=> #<CatalogEntry:0xb78109a4 @attributes={...}>


=> #<Article:0xb7517f2c @attributes={...}>

from the client rails_root i run script/console and try:


=> #<CatalogEntry:0xb72eae0c @prefix_options={}, @attributes={...}>


NoMethodError: undefined method `resource' for #<CatalogEntry:0xb72d3644>
        from ./script/../config/../config/../vendor/rails/activeresource/lib/active_resource/base.rb:218:in
        from (irb):3


You may include the resource in your xml response:
render :xml => @catalog_entry.to_xml(:include => :resource)


thanks, that saves me from doing an extra lookup when retrieving a
model with associated models. what about supporting associations in
general? something like where model.associated_models does a RESTful
find on the server?

It occurs to me that the only restful find is a get request of
associated_models.xml, which is a find(:all). client side filtering
to pick out the ones associated with model is an option but a terrible


When I first saw ActiveResource presented by DHH I thought to myself:
wouldn't it be cool if they used query parameters to provide
conditional filtering, a la find conditions? I still thank that would
be a neat approach which meshes well with the purpose for query
parameters IMO.


question: the association is polymorphic and the to_xml method wraps
the attributes in the association name. without the class name its
impossible to reconstruct the object in this case.

i suggest that to_xml work like so:
<catalog_entry class="CatalogEntry">
<resource class="Article">
   <attrib1>Article Title</attrib1>

i post this to see if work is underway but i suspect a patch is what
is really needed here :slight_smile:



I try this belongs_to and has_one relationship for ActiveResource, but
ror complains.
Then i try :include=>[:other_model_here], this gave me

<Other_model_here class="Article">
   <attrib1>Article Title</attrib1>

BUT ror complains

a = Model.find :last

ActiveRecord::UnknownAttributeError: unknown attribute: public_key

public key is attribute of Other_model_here

Any suggestion what to do? i need this attribute public_key and i don't
understand why i can't simple access it

Please help!