Thoughts on dynamic attributes

Source: Internet
Author: User

Dynamic Attribute Table

The most common practice is forum.

Currently, many forums have real estate forums. Then the post of the House will have some attributes.

For example, in a community, there are several rooms and halls, but not all posts require this. In the future, users may also define some types of attributes.

My most basic design is

For a simple second-level structure, we use two tables.

Attribute
ID
Name, such as the cell location
Displayorder (sort ID)
Controltype (a type) is used to display dropdownlist checkbox or colorpicker during foreground control.

Attributeitem
ID
Attributeid
Name
Displayorder

Attributevalues
ID
Attributeitemid xx id of the residential area
Postid (the ID forum of a major table is the topic ID. If it is a product, it is productid ...)

Such an attribute is an attribute. For example, attributeitem has a red blue green attributevalues which is not associated with a specific color.

Then, if it is a relatively large system, such as a forum, some attributes need to be classified into a forum, when this forum posts, the relevant attribute will be displayed so that users can select.

But when users want to add something for themselves? For example, the structure above the price is not suitable, because you are unlikely to define all the prices.

Attribute
ID
Name
Displayorder
Type (Int or string decimal ...)

Attributedefavalue Value
Attributeid
Defaultvalue
Displayorder

Attributevalues (many to many)
ID
Attributeid
Postid (the ID forum of a major table is the topic ID. If it is a product, it is productid ...)
Numbervalue (decimal type, convert datetime to number type)
Strvalue

If it goes further, attributevalues becomes

Attributestringvalues
ID
Attributeid
Postid (the ID forum of a major table is the topic ID. If it is a product, it is productid ...)
Strvalue

Attributedecimalvalues
ID
Attributeid
Postid (the ID forum of a major table is the topic ID. If it is a product, it is productid ...)
Decimalvalue

Attributedatetimevalues
....

 

In this way, the attribute is the color attributedefaultvalue which has the red green blue
Which side of attributevalues is the direct value?

 

It seems that this structure is called EAV.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.