Will Briggs
2007-Jun-28 18:55 UTC
Returning associated ActiveRecord data through a Rails web service
I have built a web service to allow people to query and manipulate my ActiveRecord data. Example: api_method :find_widget_by_id, :expects => [:int], :returns => [Widget] This works fairly well, since it returns my ActiveRecord "widget" class - no mess, no fuss, no hassle, no repetition. The only problem is, this class interacts with several other objects: has_and_belongs_to_many :associatedthings belongs_to :category belongs_to :otherthing belongs_to :thirdthing I would ideally like to return the entire object hierarchy as a SOAP or XML-RPC object. I have tried this in my service controller: def find_widget_by_id( id ) Widget.find( id, :include => [:associatedthings] ) end But it still just returns the "Widget" object without any of the "associatedthing" objects. I have tried it with one of the "belongs_to" objects as well, and the results are the same. Has anyone done this before? Is there any kind of Rails magic to do this, or should I build some custom return classes and shove all the data into those? I''m trying to follow the "DRY" principle in order to keep this as simple as possible, even though the brute force option would work. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---