Magento – List all EAV Attributes of an entity_type_id via SQL

eavsql

How can I obtain the list of all EAV attributes of a specific entity (by its entity_type_id) via SQL?

Best Answer

EAV attributes in the eav_attribute table are directly linked to the entity_type table. So all attributes can be revealed by a left-join query across those two tables:

-- show all eav attributes of an eav entity by entity_type_id

SET @entity_type_id = 10;

SELECT entity_type.entity_type_id, entity_type.entity_type_code
     , entity_type.entity_model
     , attribute.attribute_id, attribute.attribute_code, attribute.backend_type
    FROM eav_entity_type entity_type
    LEFT JOIN eav_attribute attribute 
        ON attribute.entity_type_id = entity_type.entity_type_id
    WHERE entity_type.entity_type_id = @entity_type_id;

Example output:

+----------------+------------------+-----------------------+--------------+----------------+--------------+
| entity_type_id | entity_type_code |     entity_model      | attribute_id | attribute_code | backend_type |
+----------------+------------------+-----------------------+--------------+----------------+--------------+
|             10 | mcd_comment      | mcd_meeting05/comment |          246 | comment        | text         |
|             10 | mcd_comment      | mcd_meeting05/comment |          249 | created_at     | static       |
|             10 | mcd_comment      | mcd_meeting05/comment |          245 | customer_id    | int          |
|             10 | mcd_comment      | mcd_meeting05/comment |          244 | guest_email    | varchar      |
|             10 | mcd_comment      | mcd_meeting05/comment |          243 | guest_name     | varchar      |
|             10 | mcd_comment      | mcd_meeting05/comment |          247 | page           | varchar      |
|             10 | mcd_comment      | mcd_meeting05/comment |          251 | product_id     | static       |
|             10 | mcd_comment      | mcd_meeting05/comment |          248 | store_id       | static       |
|             10 | mcd_comment      | mcd_meeting05/comment |          250 | updated_at     | static       |
+----------------+------------------+-----------------------+--------------+----------------+--------------+

Related non-SQL question:

Related Topic