问题描述
我是 Ember/ED/EmberFire 的新手,如果这是一个微不足道的问题,我深表歉意.我可以将记录保存到 Firebase,但无法在控制器中指定与这些记录的关系.我正在使用
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
我有一个这样的模型:
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})
});
我只是想指定与我新创建的 encounter
对象相关联的 patient
.这是我的控制器:
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: ''
});
}
}
我可以在 Firebase 中成功创建 encounter
记录,但是没有关联的 patient
属性.我得到的只是
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_')
返回一个 promise.
this.store.find('patient', '-Jl8u8Tph_w4PMAXb9H_')
returns a promise.
试试这个:
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 中指定异步belongsTo/hasMany关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!