使用 many-to-one 覆盖帆 GET 蓝图
override sails GET blueprint with many-to-one
警告:网络编程新手。我在 sails 项目中有以下内容:
// in models/User.js
// user has many videos
module.exports = {
attributes: {
videos: {
collection: 'video',
via: 'owner'
}
}
}
// in models/Video.js
// video has one user
module.exports = {
attributes: {
owner: {
model: 'user'
}
}
}
我正在使用带有 /v1 前缀的 REST 蓝图。我正在尝试覆盖 GET /v1/user/:id/video,或者创建一个自定义路由到 GET /v1/user/:id/myGetVideo
所以我尝试了以下方法:
VideoController.js 和 UserController.js 中的 find 和 findOne 方法。这些不会触发 GET /v1/user/:id/video - 我猜是因为 many-to-one 关联的处理方式不同
创建自定义路由
// 在 routes.js
module.exports.routes = {
'get /user/:id/myGetVideo': 'UserController.myGetVideo'
}
由于命名空间的原因,这不会触发任何内容,但会按预期触发 /user/:id/myGetVideo。我不想在此处添加 /v1 命名空间 b/c,它会激增并成为更改版本的问题。
那么,我该如何重写我想要的方法,或者将它放入命名空间中?重写第一个方法看起来更干净,但是 idk.
感谢您的帮助!
编辑:关于什么是更好的 REST 实践的评论 API?
通过通配符获得:
// in routes.js
module.exports.routes = { 'get /v*/user/:id/myGetVideo':'UserController.myGetVideo' }
如果前缀方案改变,则不是防弹的,但足够好
警告:网络编程新手。我在 sails 项目中有以下内容:
// in models/User.js
// user has many videos
module.exports = {
attributes: {
videos: {
collection: 'video',
via: 'owner'
}
}
}
// in models/Video.js
// video has one user
module.exports = {
attributes: {
owner: {
model: 'user'
}
}
}
我正在使用带有 /v1 前缀的 REST 蓝图。我正在尝试覆盖 GET /v1/user/:id/video,或者创建一个自定义路由到 GET /v1/user/:id/myGetVideo
所以我尝试了以下方法:
VideoController.js 和 UserController.js 中的 find 和 findOne 方法。这些不会触发 GET /v1/user/:id/video - 我猜是因为 many-to-one 关联的处理方式不同
创建自定义路由
// 在 routes.js module.exports.routes = { 'get /user/:id/myGetVideo': 'UserController.myGetVideo' }
由于命名空间的原因,这不会触发任何内容,但会按预期触发 /user/:id/myGetVideo。我不想在此处添加 /v1 命名空间 b/c,它会激增并成为更改版本的问题。
那么,我该如何重写我想要的方法,或者将它放入命名空间中?重写第一个方法看起来更干净,但是 idk.
感谢您的帮助!
编辑:关于什么是更好的 REST 实践的评论 API?
通过通配符获得:
// in routes.js
module.exports.routes = { 'get /v*/user/:id/myGetVideo':'UserController.myGetVideo' }
如果前缀方案改变,则不是防弹的,但足够好