Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Implementing Table Per Type - Table / ORM inheritance

Good day.

I was hoping some of the Phalcon pro's could offer some adice or perhaps even point to some existing public examples of implementing a TPT (Table per Type) data structure in the ORM.

Just to clarify my terminology, what I actually mean is that I have base entities as tables, and specialisations of those entities providing just the additional fields as seperate tables. So for example.

I have an Item table which contains general item data, but I also have Event which is a specialisation of Item adding event dates.

DB : Item [price, title, quantity, description] <- Event [startdate, capacity]

So event has a dependency on the Item table and all events would have a 1 to 1 relationship with Item, but there are also other "Types of Item".

In the backend, this should likely be implimented as :

Class Event extends Item { //do something so that CRUD and any critical ORM functionality works

So my question, has anyone implemtned anything like this in Phalcon? Any pointers?

Many thanks

I am on Phalcon 1.3.4


For anyone looking I found the following which looks like a fairly complete solution :

I was wondering, is there a more built in way of achieving this outcome?



Table discriminator is implemented in Phalcon 2.0: