Note that there are some explanatory texts on larger screens.

plurals
  1. POpolymorphic relationship in ember-data
    text
    copied!<p>I have three models: <strong>Company</strong>, <strong>Person</strong>, and <strong>Task</strong>. A company has many people. A person has one company. A company has many tasks. A person has many tasks. </p> <p>The task relationships are polymorphic. </p> <p>Here are my models</p> <pre><code>App.Taskable = DS.Model.extend({ tasks: DS.hasMany('task') }); App.Task = DS.Model.extend({ subject: DS.attr('string'), taskable: DS.belongsTo('taskable', { polymorphic: true}) }); App.Person = App.Taskable.extend({ firstName: DS.attr('string'), lastName: DS.attr('string'), email: DS.attr('string'), company: DS.belongsTo('company'), fullName: function() { return this.get('firstName') + ' ' + this.get('lastName'); }.property('firstName', 'lastName') }); App.Company = App.Taskable.extend({ name: DS.attr('string'), people: DS.hasMany('person') }); </code></pre> <p>Notice that <strong>Person</strong> and <strong>Company</strong> extend <strong>Taskable</strong>. I believe i have these relationships defined properly. I don't know how to lazy load the tasks though. </p> <p>Here is my person view</p> <pre><code> &lt;script type="text/x-handlebars" data-template-name='show/_person'&gt; &lt;div&gt; &lt;form class="form-horizontal" role="form"&gt; &lt;div class="form-group"&gt; &lt;label class="col-sm-2 control-label"&gt;Name&lt;/label&gt; &lt;div class="col-sm-10"&gt; &lt;p class="form-control-static"&gt;{{fullName}}&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label class="col-sm-2 control-label"&gt;Company&lt;/label&gt; &lt;div class="col-sm-10"&gt; &lt;p class="form-control-static"&gt;{{company.name}}&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;label class="col-sm-2 control-label"&gt;Tasks&lt;/label&gt; &lt;div class="col-sm-10"&gt; &lt;p class="form-control-static"&gt; {{#each task in tasks}} {{task.subject}}&lt;br /&gt; {{/each}} &lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/script&gt; </code></pre> <p>A GET request is issued for the company associated with the person but no request is made for tasks. How do i get the tasks associated with a person or company? I would expect a GET request be made to <code>people/3/tasks</code> or something similar</p>
 

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