我在两个DS.Model
类之间有以下关系:
App.DocumentType = DS.Model.extend
...
propertyTypeJoins: DS.hasMany("App.DocumentTypePropertyType")
App.DocumentTypePropertyType = DS.Model.extend
documentType: DS.belongsTo('App.DocumentType')
子记录始终是嵌入式的,永远不会单独保存:
App.Adapter.map 'App.DocumentType'
propertyTypeJoins:
embedded: 'always'
当我使用documentType
记录和n个相关DocumentTypePropertyType
记录提交事务时,出现以下错误:
"Attempted to handle event 'didCommit' on <App.DocumentTypePropertyType:ember1806:38072> while in state rootState.loaded.updated.uncommitted. Called with undefined"
查看代码,我意识到适配器的didSaveRecord
方法会向每个嵌入式记录发送didCommit
事件。这似乎完全没问题,因为孩子们被宣布与父母一起保存(见上面的embedded: 'always'
)。
引发错误是因为willCommit
事件未传播给子级,因此它们仍处于uncommitted
状态,无法在该状态下处理didCommit
。父本身已转换为inFlight
,因此不会抛出任何错误。
在我看来,观察到的行为是不一致的。应将所有事件发送给孩子或不发送。否则会出现各种不一致的行为。
似乎我正在反对,而不是使用余烬数据,所以我停下来思考我做错了什么。
你能告诉我吗?