4

I'm building a CMS (yes, yes, I know, but I enjoy it, ok? :-)) that has 'entries'. These entries have a fixed number of standard fields that can be captured in a db - id, title, date created etc. All standard stuff.

However, I also want the entries to have X amount of 'custom fields' associated with them. These custom fields would be user-defined, and may have titles, descriptions, formatting, max-length and other attributes defined. Now obviously I can store the definitions of these fields in a db table easily enough, but what is the best way to store and match up the data for each entry that corresponds to these custom fields?

ExpressionEngine does basically this same thing, and uses an entries table that has columns dynamically added to it for each custom field. But I can't believe that this is the best way to solve this problem.

Are there any better ways to structure a relational db to deal with this sort of flexible data model?

Mark Perkins
  • 260
  • 2
  • 10

1 Answers1

3

This is basically EAV (lite):

http://en.wikipedia.org/wiki/Entity-attribute-value_model

I asked literally the same question (regarding a similar topic):

Flexible forms and supporting database structure

Community
  • 1
  • 1
sunwukung
  • 2,815
  • 3
  • 41
  • 56
  • Actually after a bit of research the way expressionengine handles it with a single, extendable table is more like a kind of single table inheritance, but I'm looking into the EAV solution you suggest now to see if it would better suit my needs. – Mark Perkins Mar 09 '11 at 19:35