在基本层面上,我想有一个invoice
实体,它可以拥有和InvoiceTo
字段。InvoiceTo
字段应与IndividualCustomer
实体或CompanyCustomer
实体具有ManyToOne
关系。
到目前为止的所有阅读都使我相信这是教义继承映射的一个案例,但只是我无法对文档或迄今为止我找到的极少数讨论教义中多态关系的博客有任何意义。
我想实现如下(如果可能的话(,
// First Example, were the invoice is sent to an IndividualCustomer
$individualCustomer = $this->getDoctrine()
->getRepository(individualCustomer::class)
->find($id);
$invoiceTo = new InvoiceTo($individualCustomer);
$invoice = new Invoice();
$invoice->setAmt(100.00);
$invoice->setInvoiceTo($invoiceTo);
// Second Example, were the invoice is sent to CompanyCustomer
$companyCustomer = $this->getDoctrine()
->getRepository(companyCustomer::class)
->find($id);
$invoiceTo = new InvoiceTo($companyCustomer);
$invoice = new Invoice();
$invoice->setAmt(100.00);
$invoice->setInvoiceTo($invoiceTo);
我真的很感激任何类型的指针。出于某种原因,所有文档似乎都非常神秘。感谢您的时间和帮助。
你的字段invoiceTo
引用IndividualCustomer
或CompanyCustomer
,一个解决方案是创建一个父类;假设Customer
,IndividualCustomer
和CompanyCustomer
从中继承。从那里,您的invoiceTo
字段可以直接定位Customer
。