lundi 25 juin 2018

Storing emberjs hasMany model on server?

So here is the model structure that i currently have in place

// match.js
import DS from 'ember-data';

export default DS.Model.extend({
    name: DS.attr('string'),
    match: DS.attr('number'),
    players: DS.hasMany('player')
});
//player.js
import DS from 'ember-data';

export default DS.Model.extend({
    pid: DS.attr('number'),
    match: DS.attr('number'),
    name: DS.attr('string'),
    point: DS.attr('number'),
    home: DS.attr('boolean'),
    squard: DS.belongsTo('squard'),
    selected: DS.attr('boolean', {default: false})
});

I create a new squad on client side and use push playerss using the following code

let player - this.store.peekRecord('player', id);
let squard = this.store.peekRecord('squard', 1);
squard.get('players').pushObject(player);

I tried using squard.save() but that doesn't send the array of players with it. How can i push those changes to server ?




Aucun commentaire:

Enregistrer un commentaire