简体   繁体   中英

SailsJS blueprint matching wrong model

I'm having a tricky issue with my models and Sails' automatic blueprint matching.

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).

That endpoint for the event model would be at /event/create , but when I post to that I get a 404.

All of my files were generated with sails generate [model] and don't contain any custom Controller routes.

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/

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.

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.

In the screencast above, this would make line 12 in the user model look like this:

module.exports = _.merge(_.cloneDeep(baseModel) { ... });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM