简体   繁体   English

如何在emberfire / emder-data中指定异步Categories / To / hasMan关系?

[英]How to specify async belongsTo/hasMany relationships in emberfire/emder-data?

I am very new at Ember/ED/EmberFire so apologies if this is a trivial question. 我是Ember / ED / EmberFire的新手,如果这是一个小问题,我们深表歉意。 I am able to save records to Firebase but I am unable to specify relationships to those records in my controller. 我可以将记录保存到Firebase,但是无法在控制器中指定与这些记录的关系。 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. 我只是想说明的patient ,我的新创建的encounter对象关联。 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. 我可以在Firebase中成功创建encounter记录,但是没有关联的patient属性。 All I get is 我所得到的是

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

this.store.find('patient', '-Jl8u8Tph_w4PMAXb9H_') returns a promise. this.store.find('patient', '-Jl8u8Tph_w4PMAXb9H_')返回一个承诺。

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();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM