startork's avatar

Relationship: Using a database property table (Entity-Attribute-Value model)

I have a database structure such that a table account has properties in a table called accountPropertyValue. accountPropertyValue has an accountId column, a propertyId column (this relates to each property available, such as postcode, number, birthday etc.) and valueText, valueInteger and valueDate columns as well as a dataType column to know which valueX column to use.

Is there a nice way to build this relationship into Eloquent such that each property with propertyId x has it's own one-to-one relationship with account. Most is achievable by extending the hasOne class and creating a lot of custom rules but it would be nice to have this working more neatly. Thanks

0 likes
3 replies
startork's avatar

Hi @Tray2 There are over 100 very sparse 'columns' and it is a very old database so the EAV model made a lot of sense for us. We are looking at migrating to a fresh database in the coming years where we will look into removing any EAV structure's. Thanks

Please or to participate in this conversation.