Examples:
The primary key for group memberships is uid + nid, that is, a key built from two columns. Unless, someone is allowed to join a group twice..
See #1006348-5: Make group memberships a fieldable entity.
The primary key for languages would/could be the language code. Not sure why someone would make that an entity, though ..
Have a look at ORMs like Doctrine, they usually do support all kinds of primary keys.
As far as I understand, D7 entities must always have a numeric id as the primary key.
Of course, multi-column primary keys make a few things more difficult: They can't easily be used as array keys, etc. So a lot of code would become more ugly and heavy. Is it worth the trouble? Maybe.
Alternative: A synthetic one-column key composed from a two-column key, with things like serialize() or binary zipper.
Comments
Comment #1
jplarose CreditAttribution: jplarose commentedI would also like proper support in entities for multi-column primary keys and non-numeric primary keys.
In the meantime, for those who need to create entities right now with unsupported primary keys, you can create a new column, make it the primary key, and set the column(s) that ought to be the PK as unique.
e.g. change from :
to:
It's kludgey, but until support for a wider range of primary keys is implemented, this will may have to do.
Comment #2
SilviuChingaru CreditAttribution: SilviuChingaru commentedWhy 'group_member', shouldn't be 'gmid'? Can you explain a little how it's work? In the hook_entity_info() we specify as id the gmid?
Comment #8
Gogowitsch CreditAttribution: Gogowitsch at QuoData GmbH Quality & Statistics commentedTo have an entity table in the database have a multi-column index, you need to add your own schema class to the entity annotation:
Your own schema class should extend SqlContentEntityStorageSchema and implement getSharedTableFieldSchema. E.g. this adds a unique index to a "UserNode" entity
Comment #9
Gogowitsch CreditAttribution: Gogowitsch as a volunteer and at QuoData GmbH Quality & Statistics commentedI'd say I close this very old feature request as I believe the feature is in core already.