Don't assume relation.modelTo in case of polymorphic belongsTo

This commit is contained in:
Fabien Franzen 2014-08-07 15:39:07 +02:00
parent b3fbefdbb7
commit 1af95272fe
1 changed files with 3 additions and 1 deletions

View File

@ -342,13 +342,15 @@ Model.remoteMethod = function(name, options) {
}
Model.belongsToRemoting = function(relationName, relation, define) {
var modelName = relation.modelTo && relation.modelTo.modelName;
modelName = modelName || 'PersistedModel';
var fn = this.prototype[relationName];
define('__get__' + relationName, {
isStatic: false,
http: {verb: 'get', path: '/' + relationName},
accepts: {arg: 'refresh', type: 'boolean', http: {source: 'query'}},
description: 'Fetches belongsTo relation ' + relationName,
returns: {arg: relationName, type: relation.modelTo.modelName, root: true}
returns: {arg: relationName, type: modelName, root: true}
}, fn);
}