Replies: 3 comments 1 reply
-
Hello, if you want to use unique and exists rules, it's a bit different from Adonis v5, which was simpler I think. The only thing I found in the documentation is here. Am I missing something? For example, when creating a user, to make sure the email is unique: export const createUserValidator = vine
.compile(
vine.object({
email: vine.string().unique(async (db, value) => {
const user = await db
.from('users')
.where('email', value)
.first()
return !user
})
})
) |
Beta Was this translation helpful? Give feedback.
-
You can extend the schema type next to your rule and don't forget to add (extend) the types, otherwise you will get type errors. |
Beta Was this translation helpful? Give feedback.
-
About |
Beta Was this translation helpful? Give feedback.
-
Hello, I'm using nodejs for the first time to develop a system and I'm having a problem with it, according to the documentation: Official AdonisJS packages extend VineJS with custom rules. For example, Lucid contributes unique and exists rules to VineJS. exists rules to VineJS.
I tried
username: vine.string().unique({ table: 'users', column: 'username' })
and it says: checker is not a function. then I looked at the VineJS documentation and it says Creating custom rules, I followed the docs, but I'm having trouble with Extending schema classes, I don't knowshould be written inside which file? Or where to encapsulate it?
Beta Was this translation helpful? Give feedback.
All reactions