I have three models: Company, Person, and Task. A company has many people. A person has one company. A company has many tasks. A person has many tasks.
The task relationships are polymorphic.
Here are my models
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')
});
Notice that Person and Company extend Taskable. I believe i have these relationships defined properly. I don't know how to lazy load the tasks though.
Here is my person view
<script type="text/x-handlebars" data-template-name='show/_person'>
<div>
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<p class="form-control-static">{{fullName}}</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Company</label>
<div class="col-sm-10">
<p class="form-control-static">{{company.name}}</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Tasks</label>
<div class="col-sm-10">
<p class="form-control-static">
{{#each task in tasks}}
{{task.subject}}<br />
{{/each}}
</p>
</div>
</div>
</script>
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 people/3/tasks or something similar