开发者

Creating One-To-Many mapping where Many can be different object types

开发者 https://www.devze.com 2023-02-17 12:50 出处:网络
I am exploring the feasibility of retrofitting an existing database to开发者_开发知识库 using Doctrine.

I am exploring the feasibility of retrofitting an existing database to开发者_开发知识库 using Doctrine.

I have three tables, a StockRequest, SalesOrder, WorkOrder. StockRequest has fields Type and TypeNo. Type is used to decide whether it has a relationship with a Sales Order or a WorkOrder, and TypeNo is the key of the SalesOrder/WorkOrder.

What is the recommended method to maintain this relationship?

Reading the doctrine documentation, it mentions a repository class, which I could use to conditionally fetch based on Type, maintaining only one StockRequest Entity.

The other possibility would be to Subclass the StockRequest class so that I have SalesOrderStockRequests and WorkOrderStockRequests.


I would make it with inheritanceand relationship, example:

abstract class AbstractOrder {
 common fields
}

class SalesOrder extends AbstractOrder {

}

class WorkOrder extends AbstractOrder {

}

then

class StockRequest {
   relationship pointing to AbstractOrder
}

and when u getOrder() { return $this->order; } Doctrine can return u instanceof either SalesOrder or WorkOrder

0

精彩评论

暂无评论...
验证码 换一张
取 消