我如何不进行任何付款或状态待定的付款?
Laravel上的“ whereDoesntHave”之类的东西
谢谢!
@Entity()
export class Booking extends BaseEntity{
@Column({type: 'varchar', length: 10})
code: string
@OneToMany(() => Payment, Payment => Payment.booking, { cascade: true })
payments: Payment
}
@Entity()
export class Payment extends BaseEntity {
@ManyToOne(() => Booking, { nullable: false })
booking: Booking
@Column({ type: "float" })
amount: number
@Column()
status: PaymentStatus;
}
答案 0 :(得分:0)
首先,您应该向名为Payment
的{{1}}实体添加外键:
bookId
然后,您应该获得@Entity()
export class Payment extends BaseEntity {
@Column({nullable: true})
bookId:number;
@ManyToOne(() => Booking, { nullable: false })
@JoinColumn({ name: 'bookId' }) // <= and add JoinColumn here
booking: Booking
@Column({ type: "float" })
amount: number
@Column()
status: PaymentStatus;
}
上bookId
为空的所有预订:
Payment
await Booking.find({
relations:['payments'],
where:[
'payments.status': 'pending',
bookId: null
]
})
中的 []
代表查询中的where
。