임베디드를 항상 한 레벨에만 사용할 수 있지만 두 레벨의 심층 모델에는 사용할 수 없습니다. 내가 blabla 로 comment.text에 대한 로그 얻을 그러나 두 번째 부분은 동작하지 않습니다 긴급한 도움임베디드 데이터 멀티 레벨 계층 구조가 항상 임베디드
App.Post = DS.Model.extend(
title: DS.attr("string")
comment: DS.belongsTo("App.Comment")
)
App.Comment = DS.Model.extend(
text: DS.attr("string")
ferment: DS.belongsTo("App.Ferment")
)
App.Ferment = DS.Model.extend(
fermenter: DS.attr("string")
)
App.Adapter.map App.Post,
'comment':
embedded: "always"
App.Adapter.map App.Comment,
ferment :
embedded: "always"
# -----------------------------
App.store = App.Store.create(
adapter: App.Adapter.create()
)
# -----------------------------
App.store.adapter.load App.store, App.Post,
id: 12
comment: {text: "blabla", ferment:{fermenter:'abcd'}}
console.log App.Post.find(12).get("comment.text")
console.log App.Post.find(12).get("comment.ferment.fermenter")
이 필요합니다. Ember 데이터 저장소의 개정판 11을 사용하고 있습니다. 비슷한 문제/해결책을 가진 사람.
흥미롭게도 우리는 hasMany를 시도 했으므로 hasMany-> Comments, Comment -hasOne-> Ferment. 이 코드는 잘 작동합니다.
App.Post = DS.Model.extend(
title: DS.attr("string")
comments: DS.hasMany("App.Comment")
)
App.Comment = DS.Model.extend(
text: DS.attr("string")
ferment: DS.belongsTo("App.Ferment")
)
App.Ferment = DS.Model.extend(
fermi: DS.attr("string")
)
App.Adapter.map App.Post,
comments:
embedded: "always"
App.Adapter.map App.Comment,
ferment:
embedded: "always"
App.store = App.Store.create(
adapter: App.Adapter.create()
)
# App.store.adapter.serializer.configure(App.Comment,
# sideloadAs: 'comments'
#)
App.store.adapter.load App.store, App.Post,
id: 12
comments: [{text: "blabla", ferment:{fermi: "found fermi"}}]
console.log App.Post.find(12).get("comments.firstObject.text")
console.log App.Post.find(12).get("comments.firstObject.ferment.fermi")
이 사람이 나에게 이것을 쓰는 데 도움이 될 수 있습니다. – sudhanshu
누군가 대답이 잘 될 것입니다. !!! 인수를 JSON 변환에 옵션으로 전달할 수 없으며 매퍼를 작성하는 유일한 방법 밖에 없습니다. – sudhanshu
이제 제대로 작동합니다. – sudhanshu