Answer the question
In order to leave comments, you need to log in
How to implement createRecord in emberJS for models that have hasMany and belongsTo?
As a backend I use emberFire at the time of development (ember v2.1).
There are two models:
Categories:
Services: The
page route loads one of the selected categories into the model:
model: function (params) {
return this.store.find('services-cat', params.category_id)
}
Action to create a new service for the selected category is:
How to remake the action so that the service is saved and the category is updated according to the hasMany and belongsTo rules?
I took the serializers from the emberFire docks.
export default FirebaseSerializer.extend({
attrs: {
category: { embedded: 'always' }
}
});
and
export default FirebaseSerializer.extend({
attrs: {
services: { embedded: 'always' }
}
});
Answer the question
In order to leave comments, you need to log in
You need to save both services-cat and category.
Something like this:
action:
__createServece: function(model) {
____var servicesCat = this.store.createRecord('services-cat', {
______servName: model.servName,
______time: ...
______...
____});
____var service = this.store.createRecord('service', {
______...
______category: servicesCat
____});
// in a simple case, save services-cat and category
__service.save();
__servicesCat.save();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question