I have two models that have a relationship, team and teamMember. On a page I'm trying to set it up so that the user can add a new teamMember to a team, but when I'm calling save() it's spitting back that a team must exist, and upon further inspection Ember is not embedding the team in the POST.
team.js
export default DS.Model.extend({
...
teamMember: DS.hasMany('team-member')
}
team-member.js
export default DS.Model.extend({
...
team: DS.belongsTo('team')
}
This is what I have in my route
let teamMember = this.get('store').createRecord('teamMember');
let team = this.get('store').findRecord('team', params.teamId).then((results) => {
teamMember.set('team', results);
return results;
});
I pass the team and the teamMember to a component where I can edit the teamMember, and save it.
let teamMember = this.get('teamMember');
// get and set teamMember specific fields
teamMember.save();
When I debug from that line I can say teamMember.get('team') and get all of the data, so it seems to be properly set, but all I get from the Rails API is
{"team_member"=>{"role_id"=>"0", "phone_number"=>"8888888888"}}
And it obviously won't create a team_member without a team to associate it with.
I have a team-member.js serializer:
export default ApplicationSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
team: { embedded: 'always' }
}
});
I do have some stuff in an application serializer, so I'm wondering if it's overwriting the data somehow, but when I debug in that it's still not recognizing the existence of the team.
Aucun commentaire:
Enregistrer un commentaire