EmberFire 数据关系未正确更新
EmberFire Data Relationships not updating correctly
更新:下面是关于 Ember 数据关系的原始 post,我认为它与 EmberFire 适配器的问题以及 hasMany 数组记录的处理方式更相关。 Ember 中的本地 store
数据似乎正在适当更新,但是这些记录在商店更新后没有被推送到适当的 Firebase 数据库中。
我添加了 emberfire 和 firebase 标签,希望能在该社区中找到答案。感谢任何帮助,我很乐意根据需要提供更多信息。
我有两个用 hasMany 和 belongsTo 关系定义的模型。这是第一个 "frameworks" 模型:
// -- Frameworks Model
import DS from 'ember-data';
const { attr, hasMany } = DS;
export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
questions: { serialize: 'ids' }
}
});
export default DS.Model.extend({
name: attr('string'),
reports: hasMany('report'),
questions: hasMany('question', {async: true}),
includedFramework: attr('string'),
reportOnlyOnce: attr('string', { defaultValue: false }),
frameBuilder: attr('string', {defaultValue: "none"}),
createdAt: attr('string'),
createdBy: attr('string'),
updatedAt: attr('string'),
updatedBy: attr('string')
});
第二个"question"模型:
// -- Question Model
import DS from 'ember-data';
const { attr, hasMany, belongsTo } = DS;
export default DS.Model.extend({
framework: belongsTo('frameworks', {async: true}),
detail: attr('string'),
type: attr('string'),
createdAt: attr('string'),
createdBy: attr('string'),
position: attr('number'),
options: hasMany('option')
});
在我的路线上,我拉入了框架的模型(在本例中定义了用于测试的模型 ID):
import Ember from 'ember';
export default Ember.Route.extend({
model(params) {
let id = params.report_id;
var self = this;
return Ember.RSVP.hash({
report: this.store.find('report', id),
general: this.store.find('frameworks', '-KITSAxjdE5TiVdk-aPC')
})
}
});
出于某种原因,这个框架有一个存储在问题中的数组,其中包含 6 个不同 "questions" 中的 4 个应该属于它。我不知道为什么框架模型中也存储了 4 个,而其中 2 个没有。在我的页面模板中:
{{#each model.general.questions as |question|}}
{{#paper-item class="md-1-line"}}
<p class="question">
{{question.detail}}
</p>
<p class="option">
{{#if (eq question.type "text")}}
{{paper-input value=question.id onChange=(action (mut question.id))}}
{{/if}}
</p>
{{/paper-item}}
{{#each model.general.questions as |question|}}
对于实际存储在该 ID 的框架模型中的 4 个问题非常有效,但对其他 2 个问题无效。其他 2 个问题确实具有引用正确框架的 belongsTo 关系。
我已经尝试在框架模型中添加一个序列化程序(如上所示),但没有任何变化。
我还尝试在创建新问题时手动将问题添加到框架存储中:
framework.get('questions').then(function(question) {
return question.pushObject(newQuestion);
})
但也没有改变。
欢迎提出任何想法,我也很乐意提供任何其他相关代码片段。
这个问题似乎与 EmberFire 响应具有 belongsTo
和 hasMany
关系的模型的方式有关,其中 "parent" 模型具有 hasMany
引用创建 child
模型时,子模型不会自动更新。
已在 GitHub 上提交问题以继续研究如何解决此问题:https://github.com/firebase/emberfire/issues/412
更新:下面是关于 Ember 数据关系的原始 post,我认为它与 EmberFire 适配器的问题以及 hasMany 数组记录的处理方式更相关。 Ember 中的本地 store
数据似乎正在适当更新,但是这些记录在商店更新后没有被推送到适当的 Firebase 数据库中。
我添加了 emberfire 和 firebase 标签,希望能在该社区中找到答案。感谢任何帮助,我很乐意根据需要提供更多信息。
我有两个用 hasMany 和 belongsTo 关系定义的模型。这是第一个 "frameworks" 模型:
// -- Frameworks Model
import DS from 'ember-data';
const { attr, hasMany } = DS;
export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
questions: { serialize: 'ids' }
}
});
export default DS.Model.extend({
name: attr('string'),
reports: hasMany('report'),
questions: hasMany('question', {async: true}),
includedFramework: attr('string'),
reportOnlyOnce: attr('string', { defaultValue: false }),
frameBuilder: attr('string', {defaultValue: "none"}),
createdAt: attr('string'),
createdBy: attr('string'),
updatedAt: attr('string'),
updatedBy: attr('string')
});
第二个"question"模型:
// -- Question Model
import DS from 'ember-data';
const { attr, hasMany, belongsTo } = DS;
export default DS.Model.extend({
framework: belongsTo('frameworks', {async: true}),
detail: attr('string'),
type: attr('string'),
createdAt: attr('string'),
createdBy: attr('string'),
position: attr('number'),
options: hasMany('option')
});
在我的路线上,我拉入了框架的模型(在本例中定义了用于测试的模型 ID):
import Ember from 'ember';
export default Ember.Route.extend({
model(params) {
let id = params.report_id;
var self = this;
return Ember.RSVP.hash({
report: this.store.find('report', id),
general: this.store.find('frameworks', '-KITSAxjdE5TiVdk-aPC')
})
}
});
出于某种原因,这个框架有一个存储在问题中的数组,其中包含 6 个不同 "questions" 中的 4 个应该属于它。我不知道为什么框架模型中也存储了 4 个,而其中 2 个没有。在我的页面模板中:
{{#each model.general.questions as |question|}}
{{#paper-item class="md-1-line"}}
<p class="question">
{{question.detail}}
</p>
<p class="option">
{{#if (eq question.type "text")}}
{{paper-input value=question.id onChange=(action (mut question.id))}}
{{/if}}
</p>
{{/paper-item}}
{{#each model.general.questions as |question|}}
对于实际存储在该 ID 的框架模型中的 4 个问题非常有效,但对其他 2 个问题无效。其他 2 个问题确实具有引用正确框架的 belongsTo 关系。
我已经尝试在框架模型中添加一个序列化程序(如上所示),但没有任何变化。
我还尝试在创建新问题时手动将问题添加到框架存储中:
framework.get('questions').then(function(question) {
return question.pushObject(newQuestion);
})
但也没有改变。
欢迎提出任何想法,我也很乐意提供任何其他相关代码片段。
这个问题似乎与 EmberFire 响应具有 belongsTo
和 hasMany
关系的模型的方式有关,其中 "parent" 模型具有 hasMany
引用创建 child
模型时,子模型不会自动更新。
已在 GitHub 上提交问题以继续研究如何解决此问题:https://github.com/firebase/emberfire/issues/412