我正在尝试从两个模型(具有hasMany& belongsTo关系)设置数据并将它们保存到firebase。
'列表'数据最终会保存到firebase但不会保存到用户数据中。
我认为我在第3步做错了什么。感谢你的帮助!
it 'the test' do
system "rails new #{destination_root} -Bfq" # no bundling, force overwrite, quiet
File.write "#{destination_root}/Gemfile", "gem '#{File.basename Dir.pwd}', path: '#{Dir.pwd}'", mode: 'a'
system "cd #{destination_root} && bundle install --quiet"
# ... continue with the test as before
答案 0 :(得分:0)
重新构建您的添加逻辑以及用户定义的模型,还修改了您的路线,在编辑和查看模式下可能如下所示。这意味着您可以从" model"中返回多个项目。
// Update models
App.List = DS.Model.extend({
value: DS.attr('string')
});
App.User = DS.Model.extend({
name: DS.attr('string')
});
App.UserLists = DS.Model.extend({
user: DS.belongsTo('user'),
list: DS.belongsTo('list')
});
export default Ember.Route.extend({
LIST:SHOW ROUTE
model: function(params) {
var store = this.get('store');
var userPromise = store.find('user', params.id);
return Ember.RSVP.hash({
user: userPromise,
userList : userPromise.then(function(user) {
return store.find(userList, { WhereUserIdIs : user.get('id') })
});
});
},
actions: {
createList: function() {
var self = this;
var failure = function(reason) {
// handle stuff
};
var list = this.store.createRecord('list', {
title: this.get('title'),
});
var user = this.get('user');
var usersList = store.createRecord('userList', {
'user': user,
'list': list
});
list.save().then(function(list) {
user.save().then(function() {
userList.save().then(function() {
self.transitionTo('lists.show', list.get('id'));
}, failure);
}, failure);
}, failure);
}
});