Forum: Ruby on Rails ActiveResource with has_many

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
267de877a66aed6026e8ea4d88410a56?d=identicon&s=25 Ryan Wallace (Guest)
on 2007-06-05 20:46
(Received via mailing list)
Hi all,

I am attempting to create a small app using ActiveResource but I am
having trouble with relationships between models. It seems that
ActiveResource doesn't support has_many relationships yet. Is there
any way to return a single xml response which can be deconstructed
into a set of related models, ie:

class Item < ActiveRecord::Base
  has_many :media_links
  has_many :media_objects, :through => :media_links

class Item < ActiveResource::Base = "http://localhost:3000/"
  has_many :media_links
  has_many :media_objects, :through => :media_links

Using this ActiveResource model generates a 'undefined method
`has_many' for Item:Class' error.

I am using the following find query on the ActiveRecord side:

    @items = Item.find :all, :conditions => params[:conditions],
    :limit => params[:limit],
    :include => {:media_links => :media_object}

    respond_to do |wants|
      wants.xml { render :xml => (@items).to_xml(:include
=> :media_objects)}
This topic is locked and can not be replied to.