Doctrine 1.2 class table inheritance method?


OK, firstly, I know this is not possible with 1.2., So I'm looking for a workaround.
And no, unfortunately, I can’t use Doctrine 2 because my shared hosting server is stuck in PHP 5.2.16 and the administrator refuses to install support for PHP 5.3.

So here is my problem, the main parent-child problem:
Suppose I have a base class User and child classes Customer , Seller , Admin .

I looked at inheritance methods: I found a simple (rather useless IMO), concrete and column aggregation, and even a workaround for “inheriting a fake class table”.

I really need “class table inheritance”, in other words, User displays a separate table containing all the common values, and child tables define a map to separate tables that define only their specific columns.

I refused perfection :) in PHP 5.3, I really don't care how it will be stored in db, but my object model is REQUIRED to have all the functionality.

So what is the best choice for a workaround?

This is what I need.

  • Defining a base class with common values ​​(name, username, password, address ...)
  • Children's classes with all meanings (general and their specific)
  • In the child classes, only their variables should be displayed, and not other child classes (for example, the Client should not have workingHours , which is a value specific to the Seller)
  • I should be able to create relations in the base class and on separate child classes, and these relations should be bound to a specific class (for example, a user class should be related to the Address class, Restourant class should be related to the Orders class, Restourant should also have the Address relationship is defined ... but the administrator cannot have the Orders relationship because he has nothing to do with orders)

Querying the base table will also be nice, but as I see it, this is one of the biggest problems, it is not required.

I hope you understand my question. Any advice would be appreciated because I really don't know what to do here.

+4
source share
1 answer

I had the same problem a few days ago and I chose column aggregation inheritance. The underlying concept is not the cleanest or most beautiful solution ever invented, but it does the trick and meets all your requirements, except for one thing:

  • The base class (and table) has all user fields as child classes.
  • Child classes have all the fields they need.
  • Child classes can access fields that belong to another chields.
  • You can freely create relationships in your Doctrine schema using the parent or child classes.

The only thing that fails is what I underline in bold, but you can easily use it. You can redefine setters and getters in your child classes, for example, if someone tries to access or change the field of the Seller’s object belonging to the Client, you do not allow it (throw an exception, return false, etc.) ..).

+3
source

Source: https://habr.com/ru/post/1344983/


All Articles