Prevent error when trying to get relationship and no links have been loaded

This commit is contained in:
Toby Zerner 2015-05-30 13:58:21 +09:30
parent 731b00571c
commit a3b029accc

View File

@ -80,23 +80,29 @@ export default class Model {
static prop(name, transform) {
return function() {
var data = this.data()[name];
return transform ? transform(data) : data
return transform ? transform(data) : data;
}
}
static one(name) {
return function() {
var link = this.data().links[name];
return link && app.store.getById(link.linkage.type, link.linkage.id)
var data = this.data();
if (data.links) {
var link = data.links[name];
return link && app.store.getById(link.linkage.type, link.linkage.id);
}
}
}
static many(name) {
return function() {
var data = this.data();
if (data.links) {
var link = this.data().links[name];
return link && link.linkage.map(function(link) {
return app.store.getById(link.type, link.id)
})
});
}
}
}