this.load in Model function: No overload matches this call. #3916
-
I have try to write a function inside the Model, but the // app/Models/User.ts
import Skill from 'App/Models/Skill'
import {
column,
BaseModel,
manyToMany,
ManyToMany,
} from '@ioc:Adonis/Lucid/Orm'
export default class User extends BaseModel {
@column({ isPrimary: true })
public id: number
@manyToMany(() => Skill)
public skills: ManyToMany<typeof Skill>
public async getAllSkills(){
if(this.$preloaded.skills === undefined){
await this.load('skills') // error TS2769: No overload matches this call.
/**
Overload 1 of 2, '(callback: (preloader: PreloaderContract<this>) => void): Promise<void>', gave the following error.
Argument of type 'string' is not assignable to parameter of type '(preloader: PreloaderContract<this>) => void'.
Overload 2 of 2, '(relation: ExtractModelRelations<this>, callback?: ((builder: this[ExtractModelRelations<this>] extends ModelRelations ? this[ExtractModelRelations<...>]["builder"] : never) => void) | undefined): Promise<...>', gave the following error.
Argument of type 'string' is not assignable to parameter of type 'ExtractModelRelations<this>'.ts(2769)
*/
}
return this.skills
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
thetutlage
Sep 21, 2022
Replies: 2 comments 1 reply
-
Try public async getAllSkills(){
if(this.$preloaded.skills === undefined){
const skill: Skill = this
await skill.load('skills')
}
return this.skills
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
RomainLanz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#1872 (reply in thread)