Nested Models and controllers in sails are not working Policies

匆匆过客 提交于 2019-12-02 07:24:13

问题


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:


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' }



来源:https://stackoverflow.com/questions/33367549/nested-models-and-controllers-in-sails-are-not-working-policies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!