[V5] How can I make validations dynamic? And there is problem with preload! #1644
-
Hello folks. First problem: const advertisementId = params.id
const advertisement = await Advertisement.findBy('id', advertisementId) I use these lines for fetching ONE Advertisement. There is no problem at Advertisement's @afterFind hook like following. @belongsTo(() => Category)
public category: BelongsTo<typeof Category>;
@afterFind()
public static async preloadAllForSingle (advertisement: Advertisement) {
try {
await advertisement.preload((preloader)=>{
preloader
.preload('user')
.preload('category') // problem is in this line
})
} catch (err) {
console.log(err.message)
console.log(err.stack)
}
} But when I try to preload category in Advertisement hook, it runs Category's @Afterfetch hook. Should not it run Category's @afterFind hook? This was the first problem. Second problem is "How can I make validators dynamic?" There are a lot of request body keys that are should validated. Should I define a schema for every key? There are about 180 categories. How can I validate all? Thanks already. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Please make dedicated threads for individual issues. Every thread created should help someone in the future :) |
Beta Was this translation helpful? Give feedback.
Please make dedicated threads for individual issues. Every thread created should help someone in the future :)