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!


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


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.


You can use a JSON field even with doctrine ORM

With EAV structure, you can use indexes (as Magento does, but still transform them to flat tables).

While JSON column indexes are implemented in mysql 5.7 and Mariadb 10.2, I doubt Doctrine can handle them.