Note that there are some explanatory texts on larger screens.

plurals
  1. PORoR ActiveResource nested resources : Difference between 3.2.1 and 3.0.7
    primarykey
    data
    text
    <p>I have two simple models, clown.rb and funny_hat.rb.</p> <p>ARes 3.0.7</p> <pre><code>clown = Clown.new({:funnyHats =&gt; [{ :id =&gt; "123" },{ :id =&gt; "456" }]}) p clown #&lt;Clown:0x3091b721 @prefix_options={}, @attributes={"funnyHats"=&gt;[#&lt;FunnyHat:0x7fd8623b @prefix_options={}, @attributes={"id"=&gt;"123"}&gt;, #&lt;FunnyHat:0x3f18dc75 @prefix_options={}, @attributes={"id"=&gt;"456"}&gt;]}&gt; </code></pre> <p>ARes 3.2.1</p> <pre><code>clown = Clown.new({:funnyHats =&gt; [{ :id =&gt; "123" },{ :id =&gt; "456" }]}) p clown #&lt;Clown:0x1f38b39c @prefix_options={}, @persisted=false, @attributes={"funnyHats"=&gt;[#&lt;Clown::FunnyHat:0xbd8632b @prefix_options={}, @persisted=false, @attributes={"id"=&gt;"123"}&gt;, #&lt;Clown::FunnyHat:0x44adf91a @prefix_options={}, @persisted=false, @attributes={"id"=&gt;"456"}&gt;]}&gt; </code></pre> <p>There appears to be a difference to nested resources with ARes 3.2.1 from ARes 3.0.7. Notice how in ARes 3.2.1 output, the "Clown::FunnyHat" nodes. I recall this occurring with ARes 3.0.7 when there was no FunnyHat.rb model declared. </p> <p><strong>Question:</strong> Is this a problem that can be worked around?</p> <p><strong>Update</strong></p> <p>If I do the following in ARes 3.2.1, I get a different result.</p> <pre><code>funny_hat = FunnyHat.new() clown = Clown.new({:funnyHats =&gt; [{ :id =&gt; "123" },{ :id =&gt; "456" }]}) p clown #&lt;Clown:0x506d043e @prefix_options={}, @persisted=false, @attributes={"funnyHats"=&gt;[#&lt;FunnyHat:0x70596c33 @prefix_options={}, @persisted=false, @attributes={"id"=&gt;"123"}&gt;, #&lt;FunnyHat:0x381ba0c6 @prefix_options={}, @persisted=false, @attributes={"id"=&gt;"456"}&gt;]}&gt; </code></pre> <p>The reason this matters is because if the node is "Clown::FunnyHat", it doesn't map to the "FunnyHat" model, and therefore the instances do not have any of the instance methods or attributes of a "FunnyHat" object.</p> <p><strong>Another Interim Hack</strong></p> <p>Put the following in some initializer step or before_filter</p> <pre><code>Dir.glob("#{Rails.root}/app/models/*.rb").sort.each { |file| require_dependency file } </code></pre> <p>Thanks <a href="https://github.com/rails/rails/issues/5148" rel="nofollow">https://github.com/rails/rails/issues/5148</a></p> <p>I'm beginning to think that ActiveResource 3.2.1 is a major regression from ActiveResource 3.0.7.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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