Merge pull request #449 from fabien/fix/polymorphic-belongs-to

Don't assume relation.modelTo in case of polymorphic belongsTo
This commit is contained in:
Raymond Feng 2014-08-07 13:54:15 -07:00
commit b07aac7377
1 changed files with 3 additions and 1 deletions

View File

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