モデルがApp.Postあり、ユーザーが投稿の追加の属性を保存するようにしたい場合。最初にモデルApp.MyModelTypesを作成し、その中にすべてのmodelTypesを保存します。
App.MyModelTypes = DS.Model.extend({
modelType: DS.attr('string') // e.g. App.Post, App.Comment
attributes: DS.hasMany('App.Attribute')
});
次に、あなたApp.Postは好きなはずです:
App.Post = DS.Model.extend({
title: DS.attr('string'),
body: DS.attr('string'),
// ... other base attributes
});
次のようにモデルを定義App.Attributeします。
App.Attribute = DS.Model.extend({
name: DS.attr('string')
attrType: DS.attr('string'),
theModelType: DS.belongsTo('App.Model'),
attributeValues: DS.hasMany('App.AttributeValue')
});
ユーザーが投稿用の新しい属性を作成する場合、アプリはApp.AttributeApp.MyModelTypeに属する新しい属性を作成する必要がありますApp.Post。
最後に、投稿のカスタム属性値を格納するためのモデルが必要です。
App.AttributeValue = DS.Model.extend({
theModelType: DS.belongsTo('App.MyModelTypes'),
targetId: DS.attr('number'),
attribute: DS.belongsTo('App.Attribute'),
value: DS.attr('string') // attribute.attrType will give us the type
});
ユーザーが特定の投稿の属性値を編集するときは、に保存しpost.id、に保存targetIdしtheModelTypeますApp.Post。
それがあなたのために働くかどうか私に知らせてください。