Answer the question
In order to leave comments, you need to log in
How to store objects with many-to-many relationship in Ember.js?
I have been struggling with the problem for a long time, because I suspect that the solution is elementary. Reduced to an abstract simplified model. Suppose there is a patient and complaints
// Модель пациента
Yo.Patient = DS.Model.extend({
firstName: DS.attr('string'),
lastName: DS.attr('string'),
zhalobs: DS.hasMany('zhaloba')
});
// Модель жалобы
Yo.Zhaloba = DS.Model.extend({
title: DS.attr('string'),
patients: DS.hasMany('patient')
});
newPatient.get('zhalobs').pushObjects(zs);
newPatient.save().then(function (p) {
for (var i = 0; i < zhalobs.length; i++) {
zhalobs[i].get('patients').pushObject(p);
zhalobs[i].save();
};
});
Answer the question
In order to leave comments, you need to log in
I ran into a similar problem, I don't remember how I solved it, it seems like this:
DS.JSONSerializer.reopen({
serializeHasMany : function(record, json, relationship) {
var key = relationship.key;
var relationshipType = DS.RelationshipChange.determineRelationshipType(
record.constructor, relationship);
if (relationshipType === 'manyToNone'
|| relationshipType === 'manyToMany'
|| relationshipType === 'manyToOne') {
json[key] = Ember.get(record, key).mapBy('id');
//TODO support for polymorphic manyToNone and manyToMany relationships
}
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question