I have a form that currently saves a customer
model that has a number of hasMany relationship to a number of other models.
Sometimes the ID of the customer
model will be known and sometimes it won’t. In an ideal case I’d like to avoid creating a chain of thens()
to save each model so thought I could send the entire object to the API as follows:
{
customer: {
first_name: x,
last_name: x,
hasManyModel1: [{
id: null,
customer_id: null, //Note: Sometimes I will be able to insert this manually.
content: x
}, {
id: null,
customer_id: null,
content: x
}]
}
}
I can’t seem to get an array of objects to return under the ‘hasMany’ property though. I tried something like this:
this.customer.hasManyModel1.pushObject(event)
customer.save()
But the event
object doesn’t seem to get pushed in the POST request. I tried various combinations of false
and records
in the models serialisers but didn’t have any luck. The only time I can get what I need is by creating a second property like newHasManyModel1 :[{},{}]
which feels a bit naff.
Any feedback would be much appreciated. Let me know if I haven’t explained myself clearly enough.