I'm using Single Table Inheritance in Doctrine2 to store OAuth credentials for multiple services. I'd like to use the service's id as the primary key; however, that's not unique across all services.
I've setup the database to use the discriminator column and the service's id as the primary key, but I can't find a way to make Doctrine use the discriminator column as the key (in addition to the discriminator column). I'm using docblock annotations, and if I add the discriminator column as an @Id field I get an error:
Duplicate definition of column...in a field or discriminator column mapping.
If I only define the field as the discriminator column, any overlapping service ids update all the matching rows.
Anyway to make this work, other than just using an autogenerated it value?
For those who use Hibernate, you can (at least as of JPA 2.1). The following code perfeclty works in my environment (hibernate-entitymanager 4.3.6.Final):
Then I configure an association to Status with the following code:
You can't, the descriminator column can't be used as part of the primary key.
Why do you need STI for this use-case btw? You have to create one new class per open-id service you provide, sounds pretty annoying :-)