mirror of
https://github.com/flarum/framework.git
synced 2024-12-13 15:13: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) {
|
static prop(name, transform) {
|
||||||
return function() {
|
return function() {
|
||||||
var data = this.data()[name];
|
var data = this.data()[name];
|
||||||
return transform ? transform(data) : data
|
return transform ? transform(data) : data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static one(name) {
|
static one(name) {
|
||||||
return function() {
|
return function() {
|
||||||
var link = this.data().links[name];
|
var data = this.data();
|
||||||
return link && app.store.getById(link.linkage.type, link.linkage.id)
|
if (data.links) {
|
||||||
|
var link = data.links[name];
|
||||||
|
return link && app.store.getById(link.linkage.type, link.linkage.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static many(name) {
|
static many(name) {
|
||||||
return function() {
|
return function() {
|
||||||
var link = this.data().links[name];
|
var data = this.data();
|
||||||
return link && link.linkage.map(function(link) {
|
if (data.links) {
|
||||||
return app.store.getById(link.type, link.id)
|
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