Entity Relation Design - NFSandbox/sh_trade_backend GitHub Wiki
[!warning] The overall entities and relationship design may changes over time. You should check out the ORM Class declaration file for more up-to-date and accurate info. You could get the link to that file at the Refs chapters at the end of this article.
In this wiki page, we will briefly discuss the design of the entities and relation in this system.
Sub ER Diagrams
The image above illustrates the relationship between Users
and Item
.
- A
TradeRecord
has references to two different users, theseller
andbuyer
. TradeRecord
has a One-To-One relation with a singleItem
. Thestatus
(交易状态
) field indicates the current state of the trade which is represented as anEnum
type in Python and database.
For info about how Python Enum
works with SQLAlchemy, check out SQLAlchemy Docs - Using Enum with ORM
Image above shows sub ER diagram between User
and ContactInfo
.
Our system allows each user to have several contact info entries. Users could add several personal contact methods like QQ, WeChat, Phone Number and Email.
This feature achieved by creating a new entity ContactInfo
, Here is breakdown of some of its field:
contact_info_type
(平台
) specifies the type of the info, (e.g.:WeChat
).contact_info
(平台ID
) stores the actual contact details with the specified type, (e.g.: QQ Number for rows withcontact_info_type == 'QQ'
)
For each published Item
, users (especially prospective buyers) often have questions that aren't adequately addressed in the item description written by seller.
To accomodate such issue, our system allows any eligible user to ask question about a specific Item
.
- Any users can ask questions about
Item
. - Question could be set to public or private. Public question are visible to any users including question and answer.
- Only seller
Item
can reply the question relavant to theItem
.
Image above describes the item-tag system entities design in this system. Users could add several tags to their published Item
, while buyers have the ability to categorize their search result or recommendation flow using Tag
as filter.
There is a very classical Many-To-Many relation between Tag
and Item
entity, that is:
- An
Item
could have severalTag
attributes. - There are several
Item
objects belongs to a singleTag
.
To achieve such relation, we used one more association table besides two entities with only two fields: tag_id
and user_id
with both of them specified as Primary Key.
Outline & Overall ER Diagrams
[!note] If you are suffering issues about low image quality or image load failure, you could check out View ER Diagram DrawIO Project File Online link in Refs chapter below.
Refs
- View ER Diagram DrawIO Project File Online (Notice: You can zoom-in or zoom-out the digram online when accessing through this link)
- Full ER Diagram PNG
- ORM Class Declaration Files