我希望将id
的一列添加到发票中的项目。{p>
我遇到错误
未找到Invoice#invoiceItems的实体元数据。
我尝试了以下两种选择:
Invoice
和
class Invoice {
@OneToMany(type => InvoiceItem, invoiceItem => invoiceItem.id)
@JoinColumn()
invoiceItems: InvoiceItem[]
@RelationId((self: Invoice) => self.invoiceItems)
invoiceItemIds: number[]
}
如何为ID数组添加关系?
答案 0 :(得分:0)
您不能将@JoinColumn用于@OneToMany(请参见docs),需要在InvoiceItem类中进行配置:
@Entity()
class Invoice {
@OneToMany(type => InvoiceItem, invoiceItem => invoiceItem.invoice)
invoiceItems: InvoiceItem[];
@RelationId((self: Invoice) => self.invoiceItems)
invoiceItemIds: number[]
}
@Entity()
class InvoiceItem {
...
@ManyToOne(type => Invoice, invoice => invoice.invoiceItems)
invoice: Invoice;
...
}
我还没有使用@RelationId,但是如果您正确加入InvoiceItems,这应该可以工作。