如何在emberfire / emder-data中指定async belongsTo / hasMany关系? [英] How to specify async belongsTo/hasMany relationships in emberfire/emder-data?

查看:87
本文介绍了如何在emberfire / emder-data中指定async belongsTo / hasMany关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果这是一个微不足道的问题,我很高兴在Ember / ED / EmberFire上表示歉意。我可以将记录保存到Firebase,但是我无法指定与控制器中记录的关系。我正在使用

  DEBUG:Ember:1.10.0 
DEBUG:Ember Data:1.0.0-beta.12
DEBUG:Firebase:2.2.3
DEBUG:EmberFire:1.4.3
DEBUG:jQuery:1.11.2

我有一个模型:

  var Patient = DS.Model。扩展({
lastName:DS.attr('string'),
firstName:DS.attr('string'),
遇到:DS.hasMany('meets',{async: true})
});

var Encounter = DS.Model.extend({
dateOfEncounter:DS.attr('string'),
patient:DS.belongsTo('patient',{async: true})
});

我只是试图指定患者我新创建的对象与对象相关联。这是我的控制器:

  actions:{
registerEncounter:function(){
var newEncounter = this .store.createRecord('meets',{
dateOfEncounter:this.get('dateOfEncounter'),
patient:this.store.find('patient','-Jl8u8Tph_w4PMAXb9H_')
});

newEncounter.save();

this.setProperties({
dateOfEncounter:''
});
}
}

我可以成功创建在Firebase中遇到记录,但没有关联的患者属性。我所得到的只是



https:// github.com/firebase/emberfire/issues/232

解决方案

this.store。找到('患者','-Jl8u8Tph_w4PMAXb9H _')返回承诺。



尝试这样:


$ b $($($)$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 遇到,{
dateOfEncounter:this.get('dateOfEncounter'),
patient:pat
});

newEncounter.save();
});


I am very new at Ember/ED/EmberFire so apologies if this is a trivial question. I am able to save records to Firebase but I am unable to specify relationships to those records in my controller. I am using

DEBUG: Ember      : 1.10.0
DEBUG: Ember Data : 1.0.0-beta.12
DEBUG: Firebase   : 2.2.3
DEBUG: EmberFire  : 1.4.3
DEBUG: jQuery     : 1.11.2

I have a model as such:

var Patient = DS.Model.extend({
    lastName: DS.attr('string'),
    firstName: DS.attr('string'),
    encounters: DS.hasMany('encounter', {async: true})
});

var Encounter = DS.Model.extend({
    dateOfEncounter: DS.attr('string'),
    patient: DS.belongsTo('patient', {async: true})
});

I am simply trying to specify the patient that my newly created encounter object is associated with. This is my controller:

actions: {
        registerEncounter: function() {
            var newEncounter = this.store.createRecord('encounter', {
            dateOfEncounter: this.get('dateOfEncounter'),
            patient: this.store.find('patient', '-Jl8u8Tph_w4PMAXb9H_')         
            });

        newEncounter.save();

        this.setProperties({
            dateOfEncounter: ''
        });
    }
}

I can successfully create the encounter record in Firebase, but there is no associated patient property. All I get is

https://github.com/firebase/emberfire/issues/232

解决方案

this.store.find('patient', '-Jl8u8Tph_w4PMAXb9H_') returns a promise.

Try this:

this.store.find('patient', '-Jl8u8Tph_w4PMAXb9H_').then(function(pat) {
     var newEncounter = this.store.createRecord('encounter', {
        dateOfEncounter: this.get('dateOfEncounter'),
        patient: pat       
     });

     newEncounter.save();
});

这篇关于如何在emberfire / emder-data中指定async belongsTo / hasMany关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆