Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FindOne function not working with Postgres

company.service.ts:`

async get(id: FindOneOptions<Company>): Promise<Company | null>{    
console.log(id)
return await this.companyRespository.findOne(id);
}

company.controller.ts:

@Get(':id')
  findOneCompany(@Param('id') id: FindOneOptions<Company>){
    return this.companyService.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.

like image 945
Chickrees Avatar asked Sep 07 '25 16:09

Chickrees


2 Answers

If 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.companyRespository.findOne({where: {id}});
}

company.controller.ts:

@Get(':id') findOneCompany(@Param('id') id: string | number){ 
    return this.companyService.get(id); 
  }
like image 52
Roberto Falcon Avatar answered Sep 10 '25 07:09

Roberto Falcon


You should use findByOne rather than findOne, since findOne expects parameters such as id

like image 33
jony89 Avatar answered Sep 10 '25 06:09

jony89