简体   繁体   English

为什么预期的路线不会使用sails.js蓝图API将项目添加到模型集合中

[英]Why expected route does not add item to models collection using sails.js blueprint API

Quick question for anyone that can help relating to adding an item to a models collection. 对于任何可以与将项目添加到模型集合有关的人员的快速提问。 (eg: Adding a tag to a blog post. Many to Many relationship) Doing this through a REST API call with default blueprints. (例如:在博客文章中添加标签。多对多关系)通过具有默认蓝图的REST API调用来实现。

This works: http://host/blogpost/1/tag/add/2 这有效: http:// host / blogpost / 1 / tag / add / 2

however I would expect this to work: http://host/blogpost/1/tag/2 但是我希望它能起作用: http:// host / blogpost / 1 / tag / 2

Instead it gives a 404 not found. 相反,它给出了404未找到。

Thanks Spencer 谢谢斯宾塞

OK, thanks to @japel in the sails chat room for pointing out that there is no route for the second option. 好的,多亏了Sails聊天室中的@japel指出了第二种选择没有路线。 In fact now that I think about it, how else would the blueprint know if I want to add or remove an item without specifying the keyword, although perhaps changing from a POST to a DELETE could work. 实际上,现在我考虑了一下,尽管也许从POST更改为DELETE可能可行,但蓝图还能如何知道我是否要添加或删除项目而不指定关键字。 The comments in the docs for the blueprint API add method are somewhat misleading: http://sailsjs.org/documentation/reference/blueprint-api/add-to docs中关于blueprint API add方法的注释有些误导: http : //sailsjs.org/documentation/reference/blueprint-api/add-to

For now I can live with specifying the action in the route. 现在,我可以指定路线中的动作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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