当前位置:网站首页>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
边栏推荐
- 『渗透基础』Cobalt Strike基础使用入门_Cobalt Strike联动msfconsole
- Medical industry EDI overview
- Build personal leanote cloud notebook with Tencent cloud lightweight application server
- 2021-08-27: the normal odometer will display natural numbers in turn to indicate mileage, Kyrgyzstan
- Simple use of cache functions
- Redis pipeline technology speed and efficiency increased by 5 times
- Introduction to the "penetration foundation" cobalt strike Foundation_ Cobalt strike linkage msfconsole
- Shuttle global levitation button
- Analyzing the superiority of humanoid robot in the post human era
- 少儿编程教育在特定场景中的普及作用
猜你喜欢

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

Leetcode (question 2) - adding two numbers

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

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

Introduction to the "penetration foundation" cobalt strike Foundation_ Cobalt strike linkage msfconsole

CTF learning notes 17:iwesec file upload vulnerability-02 file name filtering bypass
![[leetcode daily question] push domino](/img/81/1c31e97d9a245816514bcf47c92107.jpg)
[leetcode daily question] push domino

解析后人类时代类人机器人的优越性

014_ TimePicker time selector

『渗透基础』Cobalt Strike基础使用入门_Cobalt Strike联动msfconsole
随机推荐
Many regulations come into effect today! The main responsibility of network security will be further implemented
How to create a virtual machine on vSphere client -- a reliable virtual machine creation tutorial
少儿编程课程改革后的培养方式
[Yunyue plan] Tencent's cloud industry opening is based on the digital marketing of games such as king / eating chicken / fighting landlords and private domain marketing
oracle数据库提示无操作权限的问题
Simple use of cache functions
5g and industrial Internet
System design: index
How the query address of cloud native monitoring data exposes the public network
How to clone virtual machines on vspere client
PHP sizeof() function
How does a R & d make a small demand bigger and bigger step by step
让孩子们学习Steam 教育的应用精髓
CTF learning notes 17:iwesec file upload vulnerability-02 file name filtering bypass
Bi-sql order by
How to set easycvr recording plan batch and single channel settings?
Hard core observation 553 AI needs to identify almost everyone in the world with hundreds of billions of photos
How RedHat 8 checks whether the port is connected
Blackmail virus prevention guide
Bi-sql where