Note that there are some explanatory texts on larger screens.

plurals
  1. PORails can't render polymorphic associations to XML?
    primarykey
    data
    text
    <p>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:</p> <pre><code>&lt;posts&gt; #&lt;Comment:0x102ed1540&gt;#&lt;Comment:0x102ecaa38&gt;#&lt;Comment:0x102ec7fe0&gt;#&lt;Comment:0x102ec3cd8&gt; &lt;/posts&gt; </code></pre> <p>Yet as_json works! When I render JSON with :include clause, the associations are rendered correctly and I get something like:</p> <pre><code>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"}] </code></pre> <p>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. </p> <p><strong>edit</strong> 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...</p> <p>The model is that I have hangouts, and each hangout has many posts which are polymorphic to comments, photos, etc.</p> <p>Controller code for XML: format.xml { render :xml => @hangouts.to_xml(:include => :users , :methods => :posts) }</p> <p>Code for json is similar (in model): def as_json(options) super(:include => :users, :methods => :posts)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload