I am working on a new application and I have a need to use an EAV
table style for a few different tables. Primarily the one I am posting
about is my users table. I need to use EAV so that custom user defined
fields can be added/displayed easily.
So far I have a simple table structure, I have a made an ERD for easy viewing.
The approach I am thinking about using is similar to this post on key value pairs.
A simple beforeSave() that matches up fields to the form name.
There is only one issue with this that I am seeing, since I am not storing
the field name(attribute_code from eav_attributes) with the value, how
would I go about matching up the form field with the attribute_code
and ultimately with the value the form field passed in?
I think the approach in the blog is fine. Except instead of looping through the data array directly, you’d have to generate a list of the applicable EAV keys first since you’re storing the keys separately. You just need to check that it exists in the data array before setting it so you don’t set empty keys.
Basically you’d use three models rather than two, since you need to take in to account the model managing the attribute labels.