@@ -18,10 +18,13 @@ module.exports = function (app, defaults) {
1818 app . remotes ( ) . after ( '**' , function ( ctx , next ) {
1919 var data ,
2020 type ,
21+ path ,
2122 options ,
2223 modelNamePlural ,
24+ modelPath ,
2325 relatedModel ,
2426 relatedModelPlural ,
27+ relatedModelPath ,
2528 relations ,
2629 model ,
2730 requestedIncludes
@@ -56,7 +59,9 @@ module.exports = function (app, defaults) {
5659 data = utils . clone ( ctx . result )
5760 model = utils . getModelFromContext ( ctx , app )
5861 modelNamePlural = utils . pluralForModel ( model )
62+ modelPath = utils . httpPathForModel ( model )
5963 type = modelNamePlural
64+ path = modelPath
6065 relations = utils . getRelationsFromContext ( ctx , app )
6166
6267 /**
@@ -83,11 +88,13 @@ module.exports = function (app, defaults) {
8388 relatedModel = relation . modelTo
8489 }
8590 relatedModelPlural = utils . pluralForModel ( relatedModel )
91+ relatedModelPath = utils . httpPathForModel ( relatedModel )
8692 primaryKeyField = utils . primaryKeyForModel ( relatedModel )
8793
8894 if ( relatedModelPlural ) {
8995 type = relatedModelPlural
9096 model = relatedModel
97+ path = relatedModelPath
9198 relations = model . relations
9299 }
93100 }
@@ -118,6 +125,7 @@ module.exports = function (app, defaults) {
118125 options = {
119126 app : app ,
120127 model : model ,
128+ modelPath : path ,
121129 method : ctx . method . name ,
122130 meta : ctx . meta ? utils . clone ( ctx . meta ) : null ,
123131 primaryKeyField : primaryKeyField ,
@@ -126,15 +134,13 @@ module.exports = function (app, defaults) {
126134 dataLinks : {
127135 self : function ( item ) {
128136 var urlComponents = url . parse ( options . host )
129- var args = [ urlComponents . protocol . replace ( ':' , '' ) , urlComponents . host , options . restApiRoot ]
130-
131- if ( relatedModelPlural ) {
132- args . push ( relatedModelPlural )
133- } else {
134- args . push ( modelNamePlural )
135- }
136-
137- args . push ( item . id )
137+ var args = [
138+ urlComponents . protocol . replace ( ':' , '' ) ,
139+ urlComponents . host ,
140+ options . restApiRoot ,
141+ path ,
142+ item . id
143+ ]
138144
139145 return utils . buildModelUrl . apply ( this , args )
140146 }
0 commit comments