title: Ember.js RESTful model relations
body: <p>I'm having an issue relating models in Ember.js in regards with retrieving data from restful server (which is served by Sails.js using MongoDB)</p>
  
  <p>My router setup is as follows:</p>
  
  <pre><code>App.Router.map(function() {
      this.route("dashboard");
      this.resource('exams', {path: "/exams"}, function() {
          this.resource('exam', {path: ":exam_id"}, function(){
              this.resource('questions', function() {
                  this.route("new");
              })
          })
          this.route("view", {path: "/:exam_id" }); // for viewing exam details
      });
  });
  </code></pre>
  
  <p>Basically I'm getting a list of available examination and is able either edit some details for each, of click on it to see associated list of questions.</p>
  
  <p>I have no problems with the Exam resource which is accessed with restful adapter like so:</p>
  
  <pre><code>http://localhost:1337/api/v1/exams
  </code></pre>
  
  <p>which yields:</p>
  
  <pre><code>{
      exams: [
          {
          user_id: "52444c03268a31ea0b000001",
          title: "Introduction test",
          private: false,
          active: false,
          showResults: false,
          random: false,
          _id: "52471342445565e74600000a"
          },
          ...
      ]
  }
  </code></pre>
  
  <p>Questions resource is not embedded and is stored is a separate collection in MongoDB and is accessed separately:</p>
  
  <pre><code>http://localhost:1337/api/v1/questions
  </code></pre>
  
  <p>with result:</p>
  
  <pre><code>{
      questions: [
          {
          _id: "52483f404617e6c728c4ed93",
          title: "What's the capital of Moscow?",
          exam_id: "52471342445565e74600000a"
          },
          {
          _id: "52483f6e4617e6c728c4ed94",
          title: "What's the capital of Switzerland?",
          exam_id: "52471342445565e74600120a"
          }
      ]
  }
  </code></pre>
  
  <p>However, questions should always be related to exams. As far as I understand you cannot nest rest routes in Ember.js yet. My ideal rest route would be:</p>
  
  <pre><code>http://localhost:1337/api/v1/exams/52471342445565e74600000a/questions
  </code></pre>
  
  <p>to get all the questions for a particular exam, but I'm not sure if this can be done. At least I never manager to get it to work.</p>
  
  <p>So to keep to keep it simple I decided to restfully query questions with exam_id to get only the list of questions associated with particular exam:</p>
  
  <pre><code>http://localhost:1337/api/v1/questions/52471342445565e74600000a //&lt;-- exam_id
  </code></pre>
  
  <p>which return the results I need... only this is not allowed by Ember.js as it thinks I'm getting a single question w/ particular ID. I also tried looking into pushing exam_id to question restful route w/ URL parameter (../?exam_id=52471342445565e74600000a) but it seems queryParams aren't a part of Ember.js yet. At least non before v 1.2 as I see on Github.</p>
  
  <p>So my question is: How do I related and query these two models by proving a foreign key?
  I really don't want to embed everything in a single thing. OR maybe there's a better way to manager relations between models?</p>
  
  <p>One caveat though: I need to be able to query server correctly to retrieve only the needed records and not sort through whole prefetched data. This is because different exams belong to different users and question to different exams are not allowed to be seen (queried) by the others.</p>
  
  <p>I'm kinda new to Ember.js so any suggestions (or better yet real world examples) are appreciated.</p>