EAV : Entity - Attribute - Value的缩写,是数据库模型的一种,使用eav建模的好处是可以动态为数据模型增加或移除属性。

1.问题提出:

假设需要定义一个实体Customer的信息,通常我们只要定义一个表为customer,并定义相应的属性即可。倘若某天需要为customer增加一个新的属性如“毕业学校”,那么就需要更改表的结构。
如果使用EAV模型则不必改变表结构。

2.Magento的EAV模型定义:

在Magento中,EAV模型相关的表定义有:

  1. eav_attribute
  2. eav_attribute_group
  3. eav_attribute_option
  4. eav_attribute_option_value
  5. eav_attribute_set
  6. eav_entity
  7. eav_entity_attribute
  8. eav_entity_datetime
  9. eav_entity_decimal
  10. eav_entity_int
  11. eav_entity_store
  12. eav_entity_text
  13. eav_entity_type
  14. eav_entity_varchar

现在让我来观察最重要的三张表
eav_entity_type,eav_entity_attribute,eav_attribute

1) eav_entity_type表用来定义实体的基本信息。

Sql代码
  1. mysql> select * from  eav_entity_type where entity_type_id=1;
  2. +----------------+------------------+-------------------+-----------------+-----------------+
  3. | entity_type_id | entity_type_code | entity_model      | attribute_model | entity_table    | +----------------+------------------+-------------------+-----------------+-----------------+
  4. |              1 | customer         | customer/customer |                 | customer/entity |
  5. +----------------+------------------+-------------------+-----------------+-----------------+

2). eav_entity_attribute表用来定义实体customer模型包含哪些属性

Sql代码
  1. mysql> select * from eav_entity_attribute  where entity_type_id='1';
  2. +---------------------+----------------+------------------+--------------------+--------------+
  3. | entity_attribute_id | entity_type_id | attribute_set_id | attribute_group_id | attribute_id |
  4. +---------------------+----------------+------------------+--------------------+--------------+
  5. |                   1 |              1 |                1 |                  1 |            1 |
  6. |                   2 |              1 |                1 |                  1 |            2 |
  7. |                   3 |              1 |                1 |                  1 |            3 |
  8. |                   4 |              1 |                1 |                  1 |            4 |
  9. |                   5 |              1 |                1 |                  1 |            5 |
  10. |                   6 |              1 |                1 |                  1 |            6 |
  11. |                   7 |              1 |                1 |                  1 |            7 |
  12. |                   8 |              1 |                1 |                  1 |            8 |
  13. |                   9 |              1 |                1 |                  1 |            9 |
  14. |                  10 |              1 |                1 |                  1 |           10 |
  15. |                  11 |              1 |                1 |                  1 |           11 |
  16. |                  12 |              1 |                1 |                  1 |           12 |
  17. |                  13 |              1 |                1 |                  1 |           13 |
  18. |                  14 |              1 |                1 |                  1 |           14 |
  19. |                  15 |              1 |                1 |                  1 |           15 |
  20. |                  16 |              1 |                1 |                  1 |           16 |
  21. +---------------------+----------------+------------------+--------------------+--------------+

3), 由上表推出customer实体包含16个属性,下面的语句查看每个属性的具体定义

Sql代码
  1. mysql> select * from eav_attribute where attribute_id<=16 and attribute_id>=1 ;
  2. +--------------+----------------+------------------+--------------+
  3. | attribute_id | entity_type_id | attribute_code   | backend_type |
  4. +--------------+----------------+------------------+--------------+
  5. |            1 |              1 | website_id       | static       |
  6. |            2 |              1 | store_id         | static       |
  7. |            3 |              1 | created_in       | varchar      |
  8. |            4 |              1 | prefix           | varchar      |
  9. |            5 |              1 | firstname        | varchar      |
  10. |            6 |              1 | middlename       | varchar      |
  11. |            7 |              1 | lastname         | varchar      |
  12. |            8 |              1 | suffix           | varchar      |
  13. |            9 |              1 | email            | static       |
  14. |           10 |              1 | group_id         | static       |
  15. |           11 |              1 | dob              | datetime     |
  16. |           12 |              1 | password_hash    | varchar      |
  17. |           13 |              1 | default_billing  | int          |
  18. |           14 |              1 | default_shipping | int          |
  19. |           15 |              1 | taxvat           | varchar      |
  20. |           16 |              1 | confirmation     | varchar      |
  21. +--------------+----------------+------------------+--------------+

所以,使用上述的模型,一旦有CUSTOMER属性定义的添加和删除,只需要增加或删除eav_entity_attribute的记录即可

3.使用EAV模型
现在,在Magento系统注册一个新的用户,看看实例数据如何存放在数据库

Sql代码
  1. mysql> select * from customer_entity            ;
  2. +-----------+----------------+------------------+------------+--------------------+
  3. | entity_id | entity_type_id | attribute_set_id | website_id | email              |
  4. +-----------+----------------+------------------+------------+--------------------+
  5. |         1 |              1 |                0 |          1 | koda.guo@gmail.com |
  6. +-----------+----------------+------------------+------------+--------------------+
  7. mysql> select * from customer_entity_varchar    ;
  8. +----------+----------------+--------------+-----------+-------------------------------------+
  9. | value_id | entity_type_id | attribute_id | entity_id | value                               |
  10. +----------+----------------+--------------+-----------+-------------------------------------+
  11. |        1 |              1 |            5 |         1 | Koda                                |
  12. |        2 |              1 |            7 |         1 | Guo                                 |
  13. |        4 |              1 |            3 |         1 | Default Store View                  |
  14. |        5 |              1 |           12 |         1 | 2256e441b74ab3454a41c821f5de1e9d:9s |
  15. +----------+----------------+--------------+-----------+-------------------------------------

从上表看到customer_entity和customer_entity_varchar用来存放相应属性的实际输入值。如:
Koda, Guo分别属性编号5,7即firstname和lastname实际值

和customer实体定义相对应的实例存放的相关表包括:

  1. customer_entity
  2. customer_entity_datetime
  3. customer_entity_decimal
  4. customer_entity_int
  5. customer_entity_text
  6. customer_entity_varchar

总结
了解Magento的EAV模型结构是扩展Magento必须的知识。其意义在于,我们常常需要扩展Magento某些实体的属性,或者创建自定义的eav模型实例。希望本文对你有所启示。

Magento 数据表结构 EAV模型详解相关推荐

  1. Ecstore 中数据表结构定义 dbschema 详解

    详解Ecstore中的数据表结构定义文件dbschema 任何系统的操作无非都是对数据库的各种操作的结合,而对于ecstore的数据库操作可能与其他常见项目有些不太一样.可能有新入手的朋友会尝试在数据 ...

  2. java 修改mysql数据库表结构_MYSQL数据库表结构优化方法详解

    摘要:这篇MySQL栏目下的"MYSQL数据库表结构优化方法详解",介绍的技术点是"mysql数据库表结构.MySQL数据库.数据库表结构.MySQL.据库表结构.数据库 ...

  3. 2导出指定表结构_大白话详解大数据hive知识点,老刘真的很用心(2)

    老刘不敢说写的有多好,但敢保证尽量用大白话把自己复习的内容详细解释出来,拒绝资料上的生搬硬套,做到有自己的了解! 01 hive知识点(2) 第12点:hive分桶表 hive知识点主要偏实践,很多人 ...

  4. mysql修改表结构例子_mysql修改表结构方法实例详解

    本文实例讲述了mysql修改表结构方法.分享给大家供大家参考.具体如下: mysql修改表结构使用ALTER TABLE语句,下面就为您详细介绍mysql修改表结构的语句写法,希望对您学习mysql修 ...

  5. oracle synonym 表结构,ORACLE SYNONYM详解

    以下内容整理自Oracle 官方文档 一 概念 A synonym is an alias for any table, view,materialized view, sequence, proce ...

  6. Tribon模型数据抽取之sx700.exe详解

    Tribon模型数据抽取之sx700.exe详解 一:简介 网络上关于Tribon模型数据抽取的论文最早流传的是2006哈尔滨工程大学姚竞争的工学硕士学位论文<TRIBON模型的数据抽取及二次开 ...

  7. Transformer 初识:模型结构+attention原理详解

    Transformer 初识:模型结构+原理详解 参考资源 前言 1.整体结构 1.1 输入: 1.2 Encoder 和 Decoder的结构 1.3 Layer normalization Bat ...

  8. Socket模型详解

    Socket模型详解 两种I/O模式 一.选择模型 二.异步选择 三.事件选择 四.重叠I/O模型 五.完成端口模型 五种I/O模型的比较 两种I/O模式 1. 两种I/O模式 阻塞模式:执行I/O操 ...

  9. TCP/IP五层模型详解

    TCP/IP五层模型详解 应用层 HTTP:简单的明文传输的请求--响应协议 HTTP数据结构: 首行 头部 空行 正文 浏览器的控制 HTTPS 定义 CA认证 SSL加密流程: 混合对称加密过程: ...

最新文章

  1. 如何使用 Ansible 和 anacron 实现自动化
  2. 一、nginx基本模块以及模块配置
  3. postgresSQL 实现数据修改后,自动更新updated_date/ts等字段
  4. django项目允许其他机器访问
  5. SpringCloud组件:Eureka的服务发现与消费
  6. Caliburn.Micro学习笔记(三)----事件聚合IEventAggregator和 IhandleT
  7. Adhesive框架系列文章--Mongodb数据服务使用实践
  8. 合肥特殊教育中专学校计算机,安徽省特殊教育中专学校
  9. Java面向对象编程篇4——内部类
  10. 苹果保修期_iPhone 保修期内哪些情况可以获得免费维修?
  11. stm32烧录软件_使用华为LiteOS Studio开发STM32物联网工程1
  12. [收藏]Visual Component Framework
  13. Ps 初学者教程,如何在图片中创建新背景?
  14. 【18.40%】【codeforces 631D】Messenger
  15. java随机数生成方法
  16. javafx 教程_Java验证(javafx)
  17. Python爬虫---爬取腾讯动漫全站漫画
  18. 查询rssi指令_RSSI测量方法及网络设备、终端设备与流程
  19. MySQLClient instal error: “raise Exception(”Wrong MySQL configuration: maybe https://bugs.mysql.com/
  20. 实战项目:设计实现一个流程编排框架(实现)

热门文章

  1. AIOps案例: 阿里巴巴的智能监控系统
  2. 会员管理系统源码 php语言开发
  3. 报错 The type类名 is already defined
  4. 记一次被“呼死你”电话骚扰的反骚扰经历
  5. Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_unicode_ci,IMPLICIT) for operat
  6. 畜牧兽医职称需要考英语和计算机,畜牧兽医专业技术职称考试试题
  7. Tableau豆瓣电影数据项目实战练习2
  8. 各国家 MCC 和 MNC 列表
  9. 为什么有时候我们在测试ESP32或ESP8266模块使用 QOUT/QIO 下载固件,程序无法正常运行? (DIO/DOUT 正常)另外ESP32功耗怎么校验?
  10. VS2019 编译 paho-mqtt-cpp 遇到的问题