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
end
on the client app there is
class CatalogEntry < ActiveResource::Base
self.site = “http://localhost:3000/”
end
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
one.
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.
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
one.
You may include the resource in your xml response:
render :xml => @catalog_entry.to_xml(:include => :resource)
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”>
Stuff
Article Title
i post this to see if work is underway but i suspect a patch is what
is really needed here
don
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.