0

First of all, happy new year :-)

I think my question would be obvious for good programmers but I didn't manage to find an answer.

Let's say I have a Customer table and I would like this Customer to have some attributes (properties). I don't want to add a new field in the Customer table every time I will add a new attribute. Moreover, customers don't have the same number of attributes.

All that we know is each attributes is known in advance (some day, I will add a 'referer', 'age', 'type_of_prefered_food' .... attributes that is not mandatory, so customers may fill the information or not).

My question is, which is the best way to manage it using CakePHP 3 and MySQL ?

Having a Customer HasMany Attributes (If think in this case I have to have a constant list of each properties ID)

OR

Having a Customer BelongsToMany Attributes (so, through a relation table)

Knowing that, which is the best : Having a attribute ID referenced by an INTEGER or a STRING ? How to retrieve a specific property ...

My question is mostly CakePHP oriented, I want to know if one approach is easier to work with. Is there a CakePHP Tools/function/library that will help me to retrieve/add/edit easily attributes to a specific Customer ?

The best question I managed to find is : How to pivot a MySQL entity-attribute-value schema

Thanks in advance for those having the time to respond.

Community
  • 1
  • 1
azerto00
  • 1,001
  • 6
  • 18
  • There is no _direct_ relation between `Customer` and `Attribute`. You need to create a third table (customers_attributes). Such that --> `Customer` HasMany `CustomerAttribute`. `CustomerAttribute` BelongsTo `Customer`. `Attribute` HasMany `CustomerAttribute`. `CustomerAttribute` BelongsTo `Attribute`. – AgRizzo Jan 07 '16 at 21:58
  • Yea... this is what I meant by saying '(so, through a relation table)'... – azerto00 Jan 08 '16 at 12:38

0 Answers0