Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2><strong>Use Erez's answer</strong></h2> <hr> <p>You asked for it - I don't know about ruby, but each website in @websites should already contain a field that has a simulation. </p> <p>This is what you're doing.</p> <p>1 - You take user, a single object, and get its websites. Cool. User looks something like this (in pseudocode):</p> <pre><code> Object @user { Array[] websites = [(Website)site1, (Website)site2]; } </code></pre> <p>Alright, that's cool. So <code>user.websites</code> should return an array of websites.</p> <p>2 - You try to get the simulations from a website. A website probably looks like this:</p> <pre><code> Object @website { Array[] simulations = [(Simulation)sim1, (Simulation)sim2]; } </code></pre> <p>Hm, why doesn't it work? Well lets break down what you're doing:</p> <pre><code>@user.websites.simulations </code></pre> <p>You're taking <code>websites</code>, which is an array, and trying to reference a variable that belongs to a <code>website</code> type and not an <code>array</code> type. <code>@user.websites</code> is an array object that holds websites, not a website itself. What you want is to get <code>@website.simulations</code>, not <code>websites.simulations</code>.</p> <p>So the first step is getting a website. That's easy - one way would be to try to fetch a website from your website array in the user.</p> <pre><code>@User.websites[0] &lt;-- may not be syntactically correct; I don't know ruby. </code></pre> <p>Now if you want to get all of the websites, iterate through them using a loop and push them to a new array. Again in pseudocode:</p> <pre><code>@all_simulations = new Array(); for(@i=0;@i&lt;count(@user.websites);@i++) //first loop through the websites { for(@q=0;@q&lt;count(@user.websites[@i].simulations);@q++) //then loop through the simulations { @all_simulations.push(@user.websites[@i].simulations[@q]); //push the simulation into @all_websites } } </code></pre> <p>What we do here is we go into each website in the <code>user.websites</code> array and then grab each simulation from that website and throw that into our <code>@all_simulations</code> variable. If you understand the concept, you should be able to convert this logic into valid ruby.</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.
    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