mirror of
https://github.com/flarum/framework.git
synced 2024-12-13 23:53:42 +08:00
Prevent error when trying to get relationship and no links have been loaded
This commit is contained in:
parent
731b00571c
commit
a3b029accc
|
@ -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)
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user