1

I have a nested model as such:

var School = DS.Model.extend({
    classrooms: DS.hasMany('classroom', {async: true})
});

var Classroom = DS.Model.extend({
    students: DS.hasMany('student', {async: true}),
    school: DS.belongsTo('school', {async: true})
});

var Student = DS.Model.extend({
    name: DS.attr('string'),
    classroom: DS.belongsTo('classroom', {async: true})
});

I am using firebase as a backend, and I understand it is advisable to denormalize the schema for efficiency sake. Is there any utility in explicitly specifying the relationship

var Student = DS.Model.extend({
    school: DS.belongsTo('school', {async: true});
});

for the Student model, even though this is implied by each Student belonging to a Classroom and each Classroom belonging to a School?

molligan
  • 35
  • 3

2 Answers2

0

I would use a computed property or a binding to get what you're after - something like

school: Ember.computed.alias('classroom.school')
schoolBinding: 'classroom.school'

It wouldn't be a DS.belongsTo because the data wouldn't actually contain a school property

jmurphyau
  • 2,309
  • 13
  • 11
0

No. You shouldn't need to provide nested relationship information unless model in question is directly accessible from the root object (hope that makes sense).

The only "benefit" of doing so is that in your case the student model will be loaded when the school data is being loaded rather than waiting until the classroom data is loaded. However, this will provide a data structure that is not reflective of your intentions and so I wouldn't advocate doing this.

trentmwillis
  • 651
  • 4
  • 6