admin管理员组文章数量:1294541
pany.service.ts:`
async get(id: FindOneOptions<Company>): Promise<Company | null>{
console.log(id)
return await thispanyRespository.findOne(id);
}
pany.controller.ts:
@Get(':id')
findOneCompany(@Param('id') id: FindOneOptions<Company>){
return thispanyService.get(id);
}
I have written the following code but whenever I try to get by FindOne my console says that "You must provide selection conditions in order to find a single row.". I tried all possible solution on the web including adding curly braces and also using other FindOptions nothing seems to make this error go away. My API platform shows an internal server error.
pany.service.ts:`
async get(id: FindOneOptions<Company>): Promise<Company | null>{
console.log(id)
return await this.panyRespository.findOne(id);
}
pany.controller.ts:
@Get(':id')
findOneCompany(@Param('id') id: FindOneOptions<Company>){
return this.panyService.get(id);
}
I have written the following code but whenever I try to get by FindOne my console says that "You must provide selection conditions in order to find a single row.". I tried all possible solution on the web including adding curly braces and also using other FindOptions nothing seems to make this error go away. My API platform shows an internal server error.
Share asked Oct 21, 2022 at 11:53 ChickreesChickrees 411 silver badge3 bronze badges 1- 1 What is the code of the CompanyRepository.findOne method ? – TLd Commented Oct 21, 2022 at 12:13
4 Answers
Reset to default 6If it's an id I don't know why it's type is an interface. I think that's why you have vscode telling you that's an error. You should as @DinuMinhea says:
service.ts
async get(id: string | number): Promise<Company | null>{
console.log(id)
return await this.panyRespository.findOne({where: {id}});
}
pany.controller.ts:
@Get(':id') findOneCompany(@Param('id') id: string | number){
return this.panyService.get(id);
}
You should use findByOne
rather than findOne
, since findOne
expects parameters such as id
async get(id: FindOneOptions<Company>): Promise<Company | null>{
console.log(id)
return await this.panyRespository.findOne({id: id});
}
Try to specify the Entity field that you're searching by. In your case this is the id
.
pany.service.ts
...
async get(id: string | number): Promise<Company | null>{
console.log(id)
return await this.panyRespository.findOne({ id });
}
本文标签: javascriptFindOne function not working with PostgresStack Overflow
版权声明:本文标题:javascript - FindOne function not working with Postgres - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741600577a2387676.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论