I have a Mysql DataBase, and I need to make a consult for return all the relations (I'm consulting to relation table) that matches with an array of Ids, so for that I'll receive the array by body and I'm planing do the next consult:
const taskRelationFound = await getRepository(TaskRelation).findOne({ where: { ProjectId: ProjectIds , IsActive: true } });
it is into a async method, and the value of projectsIds is the next: [ "ccb79423-ed2b-4650-acb4-567c5e2a6cff", "68ff86e2-1c81-4487-bc7e-dddf1507f99e" ]
ProjectIds is an array with all the Id's where I'm looking for get the relations where each Id's matches with the ProjectId column, but I'm getting an error in the consult, and I'm not sure why
My entity works with this structure:
TaskRelationId: string;
TaskId: string;
UserId: string;
ProjectId: string;
IsResponsable: boolean;
IsActive: boolean;
so how can I get all relations where ProjectId Matches with any ProjectId that I'm giving throw the array?
As you want to apply the where
clause to an array projectIds
, you need to use In
operator as follows -
import { In } from 'typeorm';
const taskRelationFound = await getRepository(TaskRelation).findOne({ where: { ProjectId: In(ProjectIds) , IsActive: true } });