I am trying to set data from two models (that has hasMany & belongsTo relationship) and save them to firebase.
'list' data ends up being saved to firebase but not user data.
I think I'm doing something wrong at step 3. I'd appreciate your help!
import Ember from 'ember';
export default Ember.Route.extend({
model: function() {
return this.store.find('list');
},
actions: {
createList: function() {
var newListTitle = this.controllerFor('lists').get('newListTitle');
var username = this.get('session.user.displayName');
alert(this.get('session.user.displayName'));
if (Ember.isBlank(newListTitle)) { return false; }
//1
var list = this.store.createRecord('list', {
title: newListTitle,
user: username,
});
//2
//this.controllerFor('lists').set('newListTitle', '');
this.controllerFor('lists').setProperties({
title: newListTitle,
user: username,
});
alert('username');
var _this = this;
//3
list.get('users').then(function(users) {
users.addObject(user);
list.save().then(function() {
user.save().then(function(list) {
_this.transitionTo('lists.show', list); //4
});
});
});
/*
//this was my old code when I only had one property to set
list.save().then(function(list) {
_this.transitionTo('lists.show', list); //4
});
*/
}
}
});
Aucun commentaire:
Enregistrer un commentaire