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

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

1. 问题提出:

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

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

2. Magento的EAV模型定义:

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

Java代码

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_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表用来定义实体的基本信息。

Sql代码

mysql>select*fromeav_entity_typewhereentity_type_id=1;

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

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

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

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

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 |

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值