7
Jak uzyskać skojarzony rekord z modelu Ember? Lub: jak uzyskać zapis z Obiektu Obietnicy?Znajdź rekord stowarzyszenia belongsTo w Ember.js
modelu klienta
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 })
});
modelu Projekt
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 })
});
metoda Find
var project = this.store.find('project', id).then(function(data) {
console.log(data.get('customer').toString());
});
Console wyjście odpowiedź
<DS.PromiseObject:ember654>
JSON
{"projects":[
{
"id":1,
"name":"test",
"number":"a310",
"description":null,
"archived":false,
"customer_id":22
}
]};
O cholera! Facepalm. Dzięki! – Slevin