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
精彩评论