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 from the server rails_root i run script/console>> CatalogEntry.find(1)=> #<CatalogEntry:0xb78109a4 @attributes={...}>>> CatalogEntry.find(1).resource=> #<Article:0xb7517f2c @attributes={...}> from the client rails_root i run script/console and try:>> CatalogEntry.find(1)=> #<CatalogEntry:0xb72eae0c @prefix_options={}, @attributes={...}>>> CatalogEntry.find(1).resourceNoMethodError: undefined method `resource'' for #<CatalogEntry:0xb72d3644> from ./script/../config/../config/../vendor/rails/activeresource/lib/active_resource/base.rb:218:in `method_missing'' from (irb):3 Don --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 11/20/06, Don Park <don.park-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 > > from the server rails_root i run script/console > >> CatalogEntry.find(1) > => #<CatalogEntry:0xb78109a4 @attributes={...}> > >> CatalogEntry.find(1).resource > => #<Article:0xb7517f2c @attributes={...}> > > from the client rails_root i run script/console and try: > >> CatalogEntry.find(1) > => #<CatalogEntry:0xb72eae0c @prefix_options={}, @attributes={...}> > >> CatalogEntry.find(1).resource > NoMethodError: undefined method `resource'' for #<CatalogEntry:0xb72d3644> > from > ./script/../config/../config/../vendor/rails/activeresource/lib/active_resource/base.rb:218:in > `method_missing'' > from (irb):3You may include the resource in your xml response: render :xml => @catalog_entry.to_xml(:include => :resource) jeremy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 11/20/06, Jeremy Kemper <jeremy-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org> wrote:> 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. thanks, don --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. Sincerely, Anthony On 11/20/06, Don Park <don.park-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 11/20/06, Jeremy Kemper <jeremy-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org> wrote: > > 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. > > thanks, > don > > > >-- Email: anthonyeden-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Cell: 808 782-5046 Current Location: Melbourne, FL --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 11/20/06, Jeremy Kemper <jeremy-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org> wrote:> 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"> <attrib1>Stuff</attrib1> <resource class="Article"> <attrib1>Article Title</attrib1> </resource> <catalog> i post this to see if work is underway but i suspect a patch is what is really needed here :) don --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hello I try this belongs_to and has_one relationship for ActiveResource, but ror complains. Then i try :include=>[:other_model_here], this gave me <Model> <attrib1>Stuff</attrib1> <Other_model_here class="Article"> <attrib1>Article Title</attrib1> </other_model_here> <catalog> BUT ror complains> a = Model.find :lastActiveRecord::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 Model.Other_model_here.public_key Please help! -- Posted via http://www.ruby-forum.com/.