I'm trying to do a search by filtering the results based on the categories, on the following entities:
@Entity()
export class Anime {
@PrimaryGeneratedColumn('uuid')
id?: string;
@Column({ nullable: false })
name: string;
@ManyToMany(type => Category)
@JoinTable()
categories: Category[];
}
@Entity()
export class Category {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ nullable: false })
name: string;
@Column({ default: 'Descrição não fornecida' })
description: string;
}
for this I am using this function that uses the find options of the typeorm as prescribed in the documentation:
constructor(
@InjectRepository(Anime) private readonly db: Repository<Anime>,
) {}
async findAll(
limit: number,
page: number,
whereOptions: WhereExpression,
orderOptions: OrderByCondition,
): Promise<Anime[]> {
try {
const animes = await this.db.find({
take: limit,
skip: page,
where: {
categories: { id: '6a999dc1-20a7-43c7-b6e2-b6eb0c883875' },
},
order: orderOptions,
join: {
alias: 'a',
leftJoinAndSelect: {
categories: 'a.categories',
},
},
relations: ['categories'],
});
return animes;
} catch (e) {
throw new SqlException(e);
}
}
The error is as follows:
"ER_BAD_FIELD_ERROR: Unknown column 'a.animeId' in 'where clause'"
I know that this column does not really exist in the anime entity, but shouldn't it be doing this filtering in the join column? can someone tell me if I am doing something wrong or how to fix this bug?