[英]SailsJS blueprint matching wrong model
I'm having a tricky issue with my models and Sails' automatic blueprint matching. 我的模型和Sails的自动蓝图匹配存在棘手的问题。
When I post to one of my endpoints, /answer/create
, I get a 500 response with validation errors for a different model entirely (the event
model). 当我发布到我的一个端点/answer/create
,我得到一个500的响应,其中完全包含针对另一个模型( event
模型)的验证错误。
That endpoint for the event
model would be at /event/create
, but when I post to that I get a 404. event
模型的端点位于/event/create
,但是当我发布到该端点时,我得到了404。
All of my files were generated with sails generate [model]
and don't contain any custom Controller routes. 我所有的文件都是通过sails generate [model]
生成的,并且不包含任何自定义的Controller路由。
Has anyone seen this before? 谁看过这个吗?
It turned out this was a result of following this screencast: http://irlnathan.github.io/sailscasts/blog/2013/09/15/sailscasts-answers-ep1-question-about-using-a-service-to-allow-inheritance-in-a-model/ 原来,这是以下屏幕录像的结果: http : //irlnathan.github.io/sailscasts/blog/2013/09/15/sailscasts-answers-ep1-question-about-using-a-service-to-允许继承-IN-A-模型/
I was inheriting a baseModel via services into more than one other model, so when I ran _.merge()
, the changes it made would persist across them both, rendering inconsistencies. 我正在通过服务将baseModel继承到一个以上的其他模型中,因此当我运行_.merge()
,对它所做的更改将在它们两者之间持久存在,从而导致不一致。
If you want to do this, make sure you use the _.cloneDeep
method to clone the base model, otherwise _.merge
will affect it and your blueprints/actions won't work as expected. 如果要执行此操作,请确保使用_.cloneDeep
方法克隆基本模型,否则_.merge
将影响它,并且您的蓝图/操作将无法按预期进行。
In the screencast above, this would make line 12 in the user model look like this: 在上面的截屏中,这将使用户模型中的第12行看起来像这样:
module.exports = _.merge(_.cloneDeep(baseModel) { ... });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.