1. 问题提出:

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

如果使用EAV模型则不必改变表结构。

2. Magento的EAV模型定义:

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

eav_attribute

eav_attribute_group

eav_attribute_option

eav_attribute_option_value

eav_attribute_set

eav_entity

eav_entity_attribute

eav_entity_datetime

eav_entity_decimal

eav_entity_int

eav_entity_store

eav_entity_text

eav_entity_type

eav_entity_varchar

现在让我来观察最重要的三张表

eav_entity_type,eav_entity_attribute,eav_attribute

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

mysql> select * from eav_entity_type where entity_type_id=1;

+----------------+------------------+-------------------+-----------------+-----------------+

| entity_type_id | entity_type_code | entity_model | attribute_model | entity_table | +----------------+------------------+-------------------+-----------------+-----------------+

| 1 | customer | customer/customer | | customer/entity |

+----------------+------------------+-------------------+-----------------+-----------------+

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

mysql> select * from eav_entity_attribute where entity_type_id='1';

+---------------------+----------------+------------------+--------------------+--------------+

| entity_attribute_id | entity_type_id | attribute_set_id | attribute_group_id | attribute_id |

+---------------------+----------------+------------------+--------------------+--------------+

| 1 | 1 | 1 | 1 | 1 |

| 2 | 1 | 1 | 1 | 2 |

| 3 | 1 | 1 | 1 | 3 |

| 4 | 1 | 1 | 1 | 4 |

| 5 | 1 | 1 | 1 | 5 |

| 6 | 1 | 1 | 1 | 6 |

| 7 | 1 | 1 | 1 | 7 |

| 8 | 1 | 1 | 1 | 8 |

| 9 | 1 | 1 | 1 | 9 |

| 10 | 1 | 1 | 1 | 10 |

| 11 | 1 | 1 | 1 | 11 |

| 12 | 1 | 1 | 1 | 12 |

| 13 | 1 | 1 | 1 | 13 |

| 14 | 1 | 1 | 1 | 14 |

| 15 | 1 | 1 | 1 | 15 |

| 16 | 1 | 1 | 1 | 16 |

+---------------------+----------------+------------------+--------------------+--------------+

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

mysql> select * from eav_attribute where attribute_id<=16 and attribute_id>=1 ;

+--------------+----------------+------------------+--------------+

| attribute_id | entity_type_id | attribute_code | backend_type |

+--------------+----------------+------------------+--------------+

| 1 | 1 | website_id | static |

| 2 | 1 | store_id | static |

| 3 | 1 | created_in | varchar |

| 4 | 1 | prefix | varchar |

| 5 | 1 | firstname | varchar |

| 6 | 1 | middlename | varchar |

| 7 | 1 | lastname | varchar |

| 8 | 1 | suffix | varchar |

| 9 | 1 | email | static |

| 10 | 1 | group_id | static |

| 11 | 1 | dob | datetime |

| 12 | 1 | password_hash | varchar |

| 13 | 1 | default_billing | int |

| 14 | 1 | default_shipping | int |

| 15 | 1 | taxvat | varchar |

| 16 | 1 | confirmation | varchar |

+--------------+----------------+------------------+--------------+

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

3. 使用EAV模型

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

mysql> select * from customer_entity ;

+-----------+----------------+------------------+------------+--------------------+

| entity_id | entity_type_id | attribute_set_id | website_id | email |

+-----------+----------------+------------------+------------+--------------------+

| 1 | 1 | 0 | 1 | koda.guo@gmail.com |

+-----------+----------------+------------------+------------+--------------------+

mysql> select * from customer_entity_varchar ;

+----------+----------------+--------------+-----------+-------------------------------------+

| value_id | entity_type_id | attribute_id | entity_id | value |

+----------+----------------+--------------+-----------+-------------------------------------+

| 1 | 1 | 5 | 1 | Koda |

| 2 | 1 | 7 | 1 | Guo |

| 4 | 1 | 3 | 1 | Default Store View |

| 5 | 1 | 12 | 1 | 2256e441b74ab3454a41c821f5de1e9d:9s |

+----------+----------------+--------------+-----------+-------------------------------------+

从上表看到customer_entity 和customer_entity_varchar用来存放相应属性的实际输入值。如:

Koda, Guo分别属性编号5,7即firstname和lastname实际值

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

customer_entity

customer_entity_datetime

customer_entity_decimal

customer_entity_int

customer_entity_text

customer_entity_varchar

总结

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

分享到:

2008-11-01 17:27

浏览 10653

评论

3 楼

osacar

2013-09-05

我最近也研究这个。

不过,我觉得它的查询效率比较担心。

因为系统里本来就是查询的操作占绝大部分。

2 楼

hnlixf

2011-12-07

今天再来看了一篇EAV,受益非浅,谢谢作者

1 楼

hnlixf

2011-08-31

谢谢作者贡献,写的很详细

mysql eav_Magento的EAV模型窥探相关推荐

  1. Magento的EAV模型窥探

    EAV : Entity - Attribute - Value 的缩写,是数据库模型的一种,使用eav建模的好处是可以动态为数据模型增加或移除属性. [color=#BF0000][b]1. 问题提 ...

  2. MySQL中存储具有不定列的数据-EAV模型

    当需要在MySQL中存储具有不定列的数据时,一种常见的解决方案是使用EAV(Entity-Attribute-Value)模型.EAV模型允许灵活地存储不同实体的不同属性,适用于属性数量不确定的情况. ...

  3. mysql eav设计模型_Magento 2数据库EAV模型结构

    EAV模型是一种数据模型,用于描述实体的数量预计会很大,但事实上,实体中要使用的属性数量并不多. Magento 2这么设计是为了灵活性,在不影响主干的基础上,任意新增删除属性. EAV模型(E -& ...

  4. Magento 2数据库EAV模型结构

     EAV模型是一种数据模型 ,用于描述实体的数量预计会很大,但事实上,实体中要使用的属性数量并不多. Magento 2这么设计是为了灵活性,在不影响主干的基础上,任意新增删除属性. EAV模型(E ...

  5. 【转】Magento 2数据库EAV模型结构

     EAV模型是一种数据模型 ,用于描述实体的数量预计会很大,但事实上,实体中要使用的属性数量并不多. Magento 2这么设计是为了灵活性,在不影响主干的基础上,任意新增删除属性. EAV模型(E ...

  6. java eav_动态自定义字段属性–Magento的EAV模型 | 学步园

    EAV : Entity - Attribute - Value 的缩写,是数据库模型的一种,使用eav建模的好处是可以动态为数据模型增加或移除属性. 1. 问题提出: 假设需要定义一个实体Custo ...

  7. 使用 Eav 模型构建可无限扩展的数据存储能力

    举个例子 假设要做一个电商的商品管理,我们先卖一些衣服,需要管理衣服的尺码.颜色.款式等信息,有一天需要卖电脑了,电脑需要 主板.CPU.显卡.内存.硬盘.散热 等信息,过几天又需要卖手机了,手机有 ...

  8. magento EAV 模型理解

    EAV模型是Zend框架的基础,而Magento项目又是建立在Zend框架的基础上的,所有了解EAV有助于了解Magento的架构原理,在开发Magento相关应用时非常有用. EAV : Entit ...

  9. 途牛原创|基于EAV模型的运营系统架构实践

    序 本文将介绍如何基于 EAV 模型,来构造一个准自动化的运营系统,服务运营研发部的相关工作. 我们的痛点 运营研发部对接三端(PC.M.APP)后台工作,劳心劳力... 头疼的稀疏表( 稀疏表通常会 ...

最新文章

  1. ldap、additional info: no global superior knowledge
  2. java设计模式4--建造者模式(Builder)
  3. 解惑:如何使用html+css+js实现旋转相册,立方体相册等动画效果
  4. 交换机三种端口模式Access、Hybrid和Trunk的理解
  5. sqlserver日志文件在哪_用友SQL SERVER数据库置疑修复实例
  6. 逻辑回归详解及Python实现
  7. myeclipse中配置maven
  8. C语言程序设计知识必备pdf,C语言程序设计基础知识要点.pdf
  9. 视频监控安防平台-GB35114和GB28181的注册信令
  10. pycharm导出依赖包_使用pycharm导出虚拟环境依赖包
  11. 个人配置--常用软件保护色设置
  12. Windows XP更新后出现“你可能是盗版软件受害者”解决方法
  13. 简单酷炫css3动画效果,CSS3使用Animate.css制作超炫的动画效果
  14. 主界面边框流动效果长时间挂机后会卡顿
  15. 抖音网红追女生小程序代码
  16. windows服务器安全设置详解攻略
  17. python运维主要做什么_运维工程师主要做什么?
  18. 毕业设计-基于微信小程序的临沂旅游应用系统
  19. 在快手工作是一种什么体验
  20. 1N系列常用整流二极管的主要参数

热门文章

  1. C# 解决上传附件大小限制
  2. window10下WSL使用Ubuntu报错: System has not been booted with systemd as init system (PID 1). Can‘t operat
  3. HTTPS中CA证书的签发及使用过程
  4. 企业级 zabbix 监控项目实战
  5. C#窗体Click事件没反应
  6. 一场技术人的年终盛典:9个老兵对2016年总结与思考
  7. python - 输入某年某月某日,判断这一天是这一年的第几天?
  8. 河工计院ACM2022寒假培训题单以及超详细题解
  9. ubuntu/linux安装Atom
  10. 编写程序实现通过有道或百度翻译url对用户输入数据进行翻译_8亿用户AI有道,超强神经网络翻译技术大解密...