I am able to use embedded always for one level but I am unable to use it for two level deep model. Need an urgent help
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")
I get log for comment.text as blabla But cannot get second part to work. I am using revision 11 of Ember data store. Any one with similar problem/solution.
Interestingly we tried hasMany so Post -hasMany-> Comments, Comment -hasOne-> Ferment. This works fine, here is the code.
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")