Skip to content
Advertisement

Custom fields / attributes model

I need to implement custom fields in a booking software. I need to extend some tables containing, for example, the user groups with dynamic attributes.

But also, a product table where each product can have custom fields (and ideally these fields could be nested).

I already made some searches about EAV but I read many negative comments, so I’m wondering which design to use for this kind of things.

I understand using EAV causes many joins to sort a page of products, but I don’t feel like I want to alter the groups/products tables, each time an attribute is created.

Note : I use Innodb

Advertisement

Answer

The only good solution is pretty much what you don’t want to do, alter the groups/products tables, each time an attribute is created. It’s a pain, yes, but it will guarantee data integrity and better performance.

If you don’t want to do that, you can create a table with TableName, FieldName, ID and value, and hold lets say:

TableName=’Customer’, FieldName=’Address’, ID =1 (customers ID), Value =’customers address’

But as you said, it will need loads of joins. I don’t think it is a good solution, I’ve seen it but wouldn’t really recommend it. Just showing because well, it is one possible solution.

Another solution would be to add several pre-defined columns on your tables like column1, column2, column3 and so on and use them as necessary. It’s a solution as worst as the previous one but I’ve seen major ERPs that use it.

Mate, based on experience, anything you will find on this area would be a huge work around and won’t be worth implementing, the headache you will have to maintain it will be bigger than adding your fields to your table. Keep it simple and correct.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement