0
我設計域類如下:Grails領域類關係多對一
class Invoice {
static hasMany = [invoiceOneLines: InvoiceLine, invoiceTwoLines: InvoiceLine]
}
class InvoiceLine {
static belongsTo = [invoice: Invoice]
}
發票線具有2種類型:invoiceOneLines
和invoiceTwoLines
。 然後,我創建new invoice line
:我做了如下:
def invoice = new Invoice().save(flush:true)
invoice.invoiceOneLines.add(new InvoiceLine().save(flush:true))
invoice.invoiceTwoLines.add(new InvoiceLine().save(flush:true))
我創建2 invoice lines as invoiceOneLines
和3 invoice lines as invoiceTwoLines
。然而,當我顯示它在視圖:
invoice.invoiceOneLines.each{}
invoice.invoiceTwoLines.each{}
這表明invoiceOneLines
已得到糾正,但在invoiceTwoLines
,這表明所有(包括invoiceOneLines and invoiceTwoLines
)。
我不確定我是否設計了正確的關係。我認爲它應該是一個臨時表(就像多對多的關係)。