I have two entities named user and permission like this:
(我有两个名为用户和许可的实体,如下所示:)
User:
(用户:)
@ObjectType()
@Entity()
export class User {
@Field()
@PrimaryGeneratedColumn('uuid')
id: string;
@Authorized()
@Field()
@Column()
@Index({
unique: true,
})
email!: string;
@Field()
@Column()
name!: string;
@ManyToMany(
type => Permission,
permission => permission.users,
)
@JoinTable()
@Field(type => [Permission])
permissions: Permission[];
}
Permission:
(允许:)
@ObjectType()
@Entity()
export class Permission {
@Field()
@PrimaryGeneratedColumn('uuid')
id: string;
@Field()
@Column()
@Index({
unique: true,
})
name!: string;
@ManyToMany(
type => User,
user => user.permissions,
)
@Field(type => [User])
users: User[];
}
Now what I need to do is to see whether the user identified by the email [email protected]
have the permission identified by the name readData
.
(现在,我需要做的是查看电子邮件[email protected]
所标识的用户是否具有名称readData
标识的权限。)
I tried to do it in the following way but it did not work: (我尝试通过以下方式进行操作,但没有成功:)
const userWithPermission = await userRepository
.createQueryBuilder('user')
.where('user.email = :email', { email: '[email protected]' })
.leftJoinAndSelect('user.permissions', 'permission')
.where('permission.name = :name', { name: 'readData' })
.execute();
ask by THpubs translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…