When submitting a model with a hasMany
relationship is there a way, using the default JSON::API adapters, to submit new objects from that relationship in a single request? For example, if I have a model:
export default class TicketModel extends Model {
@attr('string') name;
. . .
@belongsTo('org', { async: true }) org;
@hasMany('component', { async: true }) components;
@hasMany('account-ticket') accountTickets;
I have no problem submitting a save and having the component association persisted since the components already exist and have an existing id.
Parameters: {"data"=>{"id"=>"4",
"attributes"=>{"name"=>"Test with reviewer", ...},
"relationships"=>{
"org"=>{"data"=>{"type"=>"orgs", "id"=>"1"}}, ...,
"components"=>{"data"=>[{"type"=>"components", "id"=>"1"}, {"type"=>"components", "id"=>"124"}, {"type"=>"components", "id"=>"123"}]}},
"type"=>"tickets"},
"id"=>"4", "ticket"=>{}}
But, I create the account ticket models in the form so they don’t have an id. What I was hoping I’d see in the submission is something like:
"relationships" => {
"account-tickets" => { "data" => [
{"type"=> "account_tickets", "role" => "manager", "account_id"=> 1}
]
. . .
}
So that I could create those relationships on the fly on the server side. Is this outside of the “default” ember-data json::api behavior?