When I render XML with an :include clause for a polymorphic association I have, it doesn't work. I end up with the XML returning the object pointers instead of the actual objects, like:
<posts>
#<Comment:0x102ed1540>#<Comment:0x102ecaa38>#<Comment:0x102ec7fe0>#<Comment:0x102ec3cd8>
</posts>
Yet as_json works! When I render JSON with :include clause, the associations are rendered correctly and I get something like:
posts":[
{"type":"Comment","created_at":"2010-04-20T23:02:30-07:00","id":7,"content":"fourth comment"},
{"type":"Comment","created_at":"2010-04-20T23:02:26-07:00","id":6,"content":"third comment"}]
My current workaround is using XML builder, but I'm not too comfortable with that in the long run. Does anyone happen to know about this issue? I'm kind of in a catch-22 because while XML doesn't render the associations, as_json doesn't render in a kosher json format (returns an array rather than a list of hashes as proper json should) and the deserializer I'm using on the client side would require modification to parse the json correctly.
edit I'm using 2.3.5 - also I am using the has_many_polymorphs gem for polymorphic has many :through, that may be causing an issue...
The model is that I have hangouts, and each hangout has many posts which are polymorphic to comments, photos, etc.
Controller code for XML: format.xml { render :xml => @hangouts.to_xml(:include => :users , :methods => :posts) }
Code for json is similar (in model): def as_json(options) super(:include => :users, :methods => :posts)