How to do dynamic EAV attribute mapping with Laminas and Doctrine (like Magento 2)?

Hi all, I’ve been using Laminas since the transition :heart: - but I’m struggling with one last problem with entity and doctrine. Not sure it’s even possible?

But I’m trying to create entities with dynamic attributes, much like Magento does it, where we have e.g. the following tables

  • entity_cms_page
  • entity_cms_page_int
  • entity_cms_page_varchar
  • entity_cms_page_decimal
  • eav_attribute

Where “int” table contain the integer values with an entity_id and attribute_id (pointing to an attribute from the eav_attribute table), varchar for varchar attributes on so on. This would be the most flexible structure for my app, but I cannot for the love of me figure out how to map it properly in doctrine. :slightly_smiling_face:

Beware, the attributes aren’t known (could be anything) at the time of creation. Other components may add attributes of any type, which can then be used by entities.

Any help with this is greatly appreciated. :slightly_smiling_face: At least a point in the right direction would be lovely. :slightly_smiling_face: Thx!

Heya,

Totally endorse using a JSON field structure and PostgreSQL: NOT going EAV is very likely the best approach.

2 Likes

Hi @ocramius and thank you for the reply. :slight_smile:

However, it’s way too late for me to not go EAV and MySQL, as I’m already far along with my Laminas + Doctrine project. :slight_smile: Much is working great with EAV in my application, I only need some help in figuring out how to approach dynamic attributes as described in my post.

Thanks!