[英]mysql Column 'id' in where clause is ambiguous
am new to mysql and typeorm and am trying to get all the posts belonging to a specific user and i want to use the id for this operation but am getting Column 'id' in where clause is ambiguous
.我是 mysql 和 typeorm 的新手,我正在尝试获取属于特定用户的所有帖子,我想使用 id 进行此操作,但Column 'id' in where clause is ambiguous
。
this is my service这是我的服务
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { createQueryBuilder } from 'typeorm';
import { Repository } from 'typeorm/repository/Repository';
import { User } from './user.entity';
@Injectable()
export class UserService {
constructor(
@InjectRepository(User)
private readonly userRepository: Repository<User>,
) {}
async userPosts(id): Promise<User> {
return this.userRepository
.createQueryBuilder('user')
.leftJoinAndSelect('user.posts', 'post')
.where('user.id = :id', { id: id }) // whats the problem here ?
.getOne();
}
}
and thats my user entity那就是我的用户实体
import { Post } from 'src/post/post.entity';
import { Entity, Column, PrimaryGeneratedColumn, OneToMany } from 'typeorm';
@Entity()
export class User {
@PrimaryGeneratedColumn()
id: number;
@Column()
firstName: string;
@Column()
lastName: string;
@Column({ default: true })
isActive: boolean;
@OneToMany(() => Post, (post: Post) => post.user, {
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
})
posts: Post[];
}
{ id: id } You don't specify which table the id field is coming from. { id: id } 您没有指定 id 字段来自哪个表。 Did you mean: { user.id: id }您的意思是:{ user.id: id }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.