lundi 20 juin 2016

Doctrine 2 - Optimal structure design for polymorphic relations

I'm working on a framework on which I wish to integrate Doctrine.

The already established structure works this way:

  • Products table:

    • productId (PK)
  • Categories table:

    • categoryId (PK)

etc. for other entities.

Where it gets complex is that, in order to introduce a "Multi-Store" concept, the framework introduces an additional table:

  • ObjectSharing table:
    • ObjectId (PK)
    • ObjectType (PK) -> ('product', 'category', etc.)
    • StoreId (PK)

With a composite primary key on the three columns of the table.

How can I model this in Doctrine? I have tried multiple options:

  • Class table inheritance (issue with the three primary keys, and the fact that a discriminator cannot be part of a primary key)
  • Many-to-one relationships from ObjectSharing, with an abstract SharedObject entity from which I override the ids in the submethods, but I still get issues

Thanks for your help.

Aucun commentaire:

Enregistrer un commentaire