当前位置:网站首页>Zero code implements one-to-one table relationship and cascading save of infinite primary and child tables
Zero code implements one-to-one table relationship and cascading save of infinite primary and child tables
2022-06-24 05:12:00 【crudapi】
Table relation higher order
In the last article Table relationship management in , Introduces one to many 、 For one more 、 And many to many relationships , This paper mainly introduces one-to-one relation and infinite master sub table in crudapi Applications in the system .
Summary
one-on-one
One to one relationship refers to a relationship between two tables in a relational database . In a relational database, a single row in the first table can only be related to one row in the second table , And a row in the second table can only be related to a row in the first table .
In a one to many relationship , The foreign key is set up in a subtable ; In a one-on-one relationship , Foreign keys can be created in the main table or sub table , For consistency ,crudapi In the system, the one-to-one relationship of foreign keys is also established in the sub table , The advantage is that if you need to remove the table relationship in the future , There is no need to modify the main table structure .
Customer information
Customer customer In the main table , It usually stores basic information , If you have more information, you can consider storing it separately in the customer information customerProfile In the table , They can be implemented in a one-to-one relationship .
Customers and customer profiles : one-on-one ( Main sub direction )
Before creating a customer customer The table remains unchanged
Create customer profiles customerProfile surface , It mainly includes customer number field 、 Birthday 、 Gender 、 Hobbies, etc , Where customer number customerId Fields are used to establish table relationships
Establish a one-to-one relationship between master and slave directions , Customer customer The number of the table id Field , Point to customer information customerProfile Customer number of customerId Field , The English name of the relationship profile For querying associated objects , Set the navigation property name to profile.
Customer profile and customer : one-on-one ( The main direction is )
Establish a one-to-one relationship between sub principal directions , Customer information customerProfile Customer number of customerId Field , Point to the customer customer The number of the table id Field , The English name of the relationship customer For querying associated objects , Set the navigation property name to customer, It's a bit similar to the previous order and customer many to one relationship , The associated objects are customer object , But at that time, multiple orders could be associated with the same customer , Now a customer profile can only be associated with one customer .
Cascade saving of customer master sub tables
ui Create customer , At the same time, input sub table customer information ,chrome Open network request record , You can see POST body as follows :
{
"name": " Liu bei ",
"mobile": "13699998888",
"email": "[email protected]",
"profile": {
"name": " Liu Bei's information ",
"birthday": "2021-02-14",
"sex": " male ",
"hobby": " Riding a horse "
}
}among profile For customer information ,
Check customer details , Customer discovery and customer information are saved successfully at one time ! In the last article , Sales order and order line are one to many primary sub relationships ,
The subtable is in the form of an array , In a one-to-one master-child relationship, a subtable is in the form of an object , The representation is the same in the database , Foreign keys are all built in sub tables .
Direct operation of customer information
You can also create a customer profile directly , Choose to hang under the designated customer , Can achieve the same effect .
Infinite sub table
By setting table relationships , One to many and one to one ( Main sub direction ) In theory, it can go on indefinitely , All tables are saved in cascade at one time , For example, provinces and cities can usually achieve 3 Stage sub table , The catalog file belongs to an infinite sub table .
Three level sub table of province and city
There is a one to many relationship between province and city , City and district are one to many .
ui effect , Jiangsu Province includes Nanjing and Huai'an , Nanjing also includes Jiangning District and Yuhuatai District .
Directory infinite sub table
The first level directory can include subdirectories and files , If it's a subdirectory , Subdirectories can continue to include subdirectories and files
Graph catalog infinite sub table -1
Graph catalog infinite sub table -2
ui effect , Sub tables include directories and files , It can go on , Because of the screen size , I don't want to show them all here .
Query directory list
Summary
This article introduces the one-to-one relationship , Including the main sub direction and the sub main direction , Plus one to many in an article , For one more , Many to many relationship , So far all the table relationships have been implemented .crudapi The system realizes the association between objects through configuration , The main sub table is realized without programming CRUD operation .
attach demo demonstration
This system belongs to the product level zero code platform , Unlike automatic code generators , You don't have to generate Controller、Service、Repository、Entity And so on , The program can be used as soon as it runs , real 0 Code , It can cover basic business independent CRUD RESTful API.
Official website address :https://crudapi.cn
Address of the test :https://demo.crudapi.cn/crudapi/login
边栏推荐
- What domain name does not need to be filed? What should be done for domain name filing
- Bi-sql distinct
- What is the domain name of the website? How much is a domain name
- Troubleshooting for the error message "[err] mod\u local\u stream.c:880 unknown source default" in easyrtc
- Have you got the programmer's drawing tools and skills?
- How can the website be broken by CC attack?
- MySQL cases MySQL find out who holds the row lock (RC)
- Shutter - how to copy certain elements from a map to a new map in dart/shutter?
- Understanding OAuth 2.0
- Verifying data models in golang
猜你喜欢

Hard core observation 553 AI needs to identify almost everyone in the world with hundreds of billions of photos

Loss and optimization of linear regression, machine learning to predict house prices

Leetcode question brushing (question 3) - the longest substring without repeated characters

解析90后创客教育的主观积极性

What is the new generation cloud computing architecture cipu of Alibaba cloud?

What are the disadvantages of the free IP address replacement tool?

011_ Cascader cascade selector

Leetcode (question 1) - sum of two numbers

Analysis on the subjective enthusiasm of post-90s makers' Education

"Emergency response practice" logparser log analysis practice
随机推荐
What's wrong with the failure of uploading web pages to ECS? How many kinds of servers are there
少儿编程课程改革后的培养方式
Hard core observation 553 AI needs to identify almost everyone in the world with hundreds of billions of photos
Spirit breath development log (11)
Is it useful to build an industrial knowledge map platform?
Inventory of common tools used by dry goods | data journalists
Drawing axes with dates using Matplotlib
Fluent version control FVM
Bi-sql insert into
PHP sizeof() function
Analysis of electronic signature system
[Tencent cloud] new enterprise users go to the cloud & the latest discount 2022!
『渗透基础』Cobalt Strike基础使用入门_Cobalt Strike联动msfconsole
查找GBase 8c数据库当前索引?
Understanding OAuth 2.0
Panoramic recording, WYSIWYG new recording scheme, and exclusive preferential resource package as low as 1 yuan!
The conference assistant hidden in wechat is the best way to work efficiently!
问题:sql创建存储过程
How to create a virtual machine on vSphere client -- a reliable virtual machine creation tutorial
4G industrial VPN router