We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

ENTITY_TYPE vs. ENTITY_ID | Forum

Matthew
Matthew Jan 25 '12
I'm moving along in the development of one of my plugins, but having a tough time trying to decipher when I should use ENTITY_TYPE and when I should use ENTITY_ID when querying a database table.  I could hardcode my query in, but that seems...bad.  

Can anyone give a quick rundown on the two, so I can conform to the norms with my coding?
Matthew
Matthew Jan 25 '12
My guess is that the column name would be ENTITY_TYPE (age, for instance).  But is the ENTITY_ID the value in a cell (18, continuing with the example) or is it something else?
Sardar
Sardar Feb 3 '12
Matthew,
ENTITY_TYPE and ENTITY_ID are not some kind of DB abstraction names. They are just table column names, like `id`, `username`, etc. They usually used in cross-feature components, like comments and rates.

For example in comments component we need to store in database - `blogId`, `eventId`, `photoId`. It is very inconvenient to create special field for every feature, that's why we use `entityType` - to store feature type and `entityId` to store item id. Thus, if you find DB entry containing `
entityType` = 'photo' and `entityId` = 10, it means that this comment was posted to photo with `id` = 10.

Concerning 
ENTITY_TYPE and ENTITY_ID, they are class constants added for code completion.

The Forum post is edited by Sardar Feb 3 '12
Michael I.
Michael I. Dec 21 '12
Topic was moved from Plugins.