views:

58

answers:

1

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?

+1  A: 

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 :-)

beberlei
It's not that bad, since the individual service classes provide access to the service, they all just extend a Mapped Superclass to persist the common OAuth data. That way I relate a `$client` to various services. So after laoding a `$client` calling `$client->twitter->user->show($id)` would get a twitter user's data using the OAuth credentials of that `$client` Entity. I'm sure there are other/better ways to do this, but it's working reasonable well for now.
Tim Lytle