Forum: Ruby on Rails Returning associated ActiveRecord data through a Rails web s

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9b7647d55df4584d7031130915556040?d=identicon&s=25 Will Briggs (Guest)
on 2007-06-28 20:56
(Received via mailing list)
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.
This topic is locked and can not be replied to.