I will be working on a system that will be using an EAV structure to store object data. The model itself will have some pre-defined attributes (coordinates and date/time stamps), namely:
- X
- Y
- Z
- start date/time
- end date/time
The rest of the attributes will be dynamically created by the user, and added as rows in the attributes table. These rows will be pivoted and used as columns to align with the values table (wasn't sure if this required an explanation, but figured better safe than sorry).
The object (or entity) to attributes relationship is one-to-many.
The attribute to values relationship is one-to-many.
I am new to Eloquent/Laravel but I have read through the relationships documentation and see that there is functionality for one-to-many relationships, however, I am unclear how I can reference all the data in an EAV (seems more geared toward RDBMS). Would it be something like this (please keep in mind this is a crude example)?
class UserObject extends Eloquent {
public function object_data()
{
return $this->hasMany(attributes_data);
}
public function attributes_data()
{
return $this->hasMany('Values');
}
}
Basically, my question is:
Is there an accepted (or proper) approach for designing/writing a model when retrieving all data associated with an EAV? If so, can you point me towards some documentation or tutorials for Eloquent/EAV approaches?
Some after thoughts:
My thinking was that I would need to create 3 classes for each component of the EAV (i.e. one for the entity component data, one for the attributes data, and one for the values data).
Thank you.