【发布时间】:2021-10-14 07:37:37
【问题描述】:
我正在关注官方 [文档] (https://legacy.adonisjs.com/docs/4.0/validator) && indicative,但我找不到任何可以帮助我的东西。
我想验证给定的参数是否存在于数据库中。
所以我尝试了:
app/Validators/myValidator
const { rule } = use('Validator')
get rules () {
return {
userId: 'required|integer|exists:MyDatabase.users,userId', <-- this is what isn't working
date: [
rule('date'),
rule('dateFormat', 'YYYY-MM-DD')
]
}
}
// Getting the data to be validated
get data () {
const params = this.ctx.params
const { userId, date } = params
return Object.assign({}, { userId }, { date })
}
它给了我以下错误:
{
"error": {
"message": "select * from `MyDatabase`.`users`.`userId` where `undefined` = '2' limit 1 - ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`userId` where `undefined` = '2' limit 1' at line 1",
"name": "ErrorValidator",
"status": 40
}
}
我应该如何正确表明我想将MyDatabase.users.userid 与给定参数进行比较?
【问题讨论】:
标签: adonis.js indicative