Nested Models and controllers in sails are not working Policies

477 views Asked by At

Continuation of this bug :

API Versioning in SailsJS

Sails Permissions AuditPolicy is not working properly. can any one guide me to do.

O/P:

   error: Sending 500 ("Server Error") response:
   Error: Invalid route option, "model".
     I don't know about any models named: `v1/user`
   at Object.module.exports.parseModel (E:\demo- server\node_modules\sails\lib\hooks\blueprints\actionUtil.js:266:25)
at ModelPolicy (E:\demo-server\node_modules\sails-permissions\api\policies\ModelPolicy.js:8:42)
at routeTargetFnWrapper (E:\demo-server\node_modules\sails\lib\router\bind.js:179:5)
at callbacks (E:\demo-server\node_modules\sails\node_modules\express\lib\router\index.js:164:37)
at param (E:\demo-server\node_modules\sails\node_modules\express\lib\router\index.js:138:11)
at pass (E:\demo-server\node_modules\sails\node_modules\express\lib\router\index.js:145:5)
at nextRoute (E:\demo-server\node_modules\sails\node_modules\express\lib\router\index.js:100:7)
at callbacks (E:\demo-server\node_modules\sails\node_modules\express\lib\router\index.js:167:11)
at E:\demo-server\node_modules\sails\lib\router\bind.js:187:7
at _sendHeaders (E:\demo-server\node_modules\sails\lib\hooks\cors\index.js:191:4)
at routeTargetFnWrapper (E:\demo-server\node_modules\sails\lib\router\bind.js:179:5)
at callbacks (E:\demo-server\node_modules\sails\node_modules\express\lib\router\index.js:164:37)
at param (E:\demo-server\node_modules\sails\node_modules\express\lib\router\index.js:138:11)
at pass (E:\demo-server\node_modules\sails\node_modules\express\lib\router\index.js:145:5)
at nextRoute (E:\demo-server\node_modules\sails\node_modules\express\lib\router\index.js:100:7)
at callbacks (E:\demo-server\node_modules\sails\node_modules\express\lib\router\index.js:167:11)
at E:\demo-server\node_modules\sails\lib\router\bind.js:187:7
at sails.router.bind._middlewareType (E:\demo-server\node_modules\sails\lib\hooks\csrf\index.js:102:11)
at routeTargetFnWrapper (E:\demo-server\node_modules\sails\lib\router\bind.js:179:5)
at callbacks (E:\demo-server\node_modules\sails\node_modules\express\lib\router\index.js:164:37)
at param (E:\demo-server\node_modules\sails\node_modules\express\lib\router\index.js:138:11)
at pass (E:\demo-server\node_modules\sails\node_modules\express\lib\router\index.js:145:5)
at nextRoute (E:\demo-server\node_modules\sails\node_modules\express\lib\router\index.js:100:7)
at callbacks (E:\demo-server\node_modules\sails\node_modules\express\lib\router\index.js:167:11)
at E:\demo-server\node_modules\sails\lib\router\bind.js:187:7
at _addResViewMethod (E:\demo-server\node_modules\sails\lib\hooks\views\res.view.js:325:3)
at routeTargetFnWrapper (E:\demo-server\node_modules\sails\lib\router\bind.js:179:5)
at callbacks (E:\demo-server\node_modules\sails\node_modules\express\lib\router\index.js:164:37) [Error: Invalid route option, "model".
I don't know about any models named: `v1/user`]

Appreciate your patience, Its my road block kindly guide me.

 silly: Registering model `v1-user` in Waterline (ORM)
  E:\demo-server\node_modules\sails\node_modules\waterline\node_modules\waterline-schema\lib\waterline-schema\foreignKeys.js:82
throw new Error('Trying to access a collection ' + collection + ' that is not defined.');
^

     Error: Trying to access a collection user that is not defined.
at ForeignKeys.findPrimaryKey (E:\demo-server\node_modules\sails\node_modules\waterline\node_modules\waterline-schema\lib\waterline-schema\foreignKeys.js:82:11)
at ForeignKeys.replaceKeys (E:\demo-server\node_modules\sails\node_modules\waterline\node_modules\waterline-schema\lib\waterline-schema\foreignKeys.js:53:27)
1

There are 1 answers

1
Meeker On

How are you attempting to access your model if blueprints are disabled, because it looks as if your trying to use blueprints, but your last question said they were disabled. In any case:

Models currently can not exist in subfolders.

To do what you're trying to do you might just prefix your models instead. It's the only way I could think to do that.

models/V1-User.js models/v1-stuff.js models/v2-user.js models/v2-stuff.js

and have your config module.exports = { _config: { model: 'V1-User' }