7
Emberモデルから関連レコードを取得するにはどうすればよいですか?または:Promiseオブジェクトからレコードを取得する方法は?Ember.jsのbelongsTo関連付けからレコードを検索
カスタマー・モデル
Docket.Customer = DS.Model.extend({
name: DS.attr('string'),
initial: DS.attr('string'),
description: DS.attr('string'),
number: DS.attr('string'),
archived: DS.attr('boolean'),
projects: DS.hasMany('project',{ async: true })
});
プロジェクトモデル
Docket.Project = DS.Model.extend({
name: DS.attr('string'),
description: DS.attr('string'),
number: DS.attr('string'),
archived: DS.attr('boolean'),
customer: DS.belongsTo('customer', { async: true })
});
Findメソッド
var project = this.store.find('project', id).then(function(data) {
console.log(data.get('customer').toString());
});
コンソール出力
<DS.PromiseObject:ember654>
JSONレスポンス
{"projects":[
{
"id":1,
"name":"test",
"number":"a310",
"description":null,
"archived":false,
"customer_id":22
}
]};
にし、別のを使用! Facepalm。ありがとう! – Slevin