当前位置:网站首页>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 is the experience of developing an ice 3D music player in 3 minutes?
- 解析90后创客教育的主观积极性
- Panoramic recording, WYSIWYG new recording scheme, and exclusive preferential resource package as low as 1 yuan!
- Bi-sql insert into
- [jest] summary of the use of automated test jest
- 3 minutes to understand JSON schema
- What are clustering, distribution, and microservices?
- System design: Agent & redundancy & replication
- Build your unique online image
- [Tencent cloud] buy a cloud server, participate in a gift lottery, and give you an iPad worth 8000 yuan, Bose earphones, and a thousand yuan JD card!
猜你喜欢

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

Training methods after the reform of children's programming course

让孩子们学习Steam 教育的应用精髓

Analyzing the superiority of humanoid robot in the post human era

Popularization of children's programming education in specific scenarios

Leetcode (question 2) - adding two numbers

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

少儿编程课程改革后的培养方式

011_ Cascader cascade selector
![[leetcode daily question] push domino](/img/81/1c31e97d9a245816514bcf47c92107.jpg)
[leetcode daily question] push domino
随机推荐
How to clone virtual machines on vspere client
Problem: SQL create stored procedure
Introduction to ebpf
5g and industrial Internet
Webmeng: create a website you are proud of
What is the use of domain name cloud resolution? What are the factors for domain name errors
Deep learning NLP from RNN LSTM Gru seq2seq to attention classification and analysis
The most complete regular expression summary in the whole network, so that you can get twice the result with half the effort. Collect it quickly
Before creating an image, it is recommended to execute the following code to purify the image as an administrator
CTF learning notes 17:iwesec file upload vulnerability-02 file name filtering bypass
What's wrong with the failure of uploading web pages to ECS? How many kinds of servers are there
Is there a free ECS? What should I pay attention to when I rent a server
3 minutes to understand JSON schema
Analysis of PHP environment configuration
Automatically convert local pictures to network pictures when writing articles
How does a R & d make a small demand bigger and bigger step by step
Tencent conference rest API x-tc-registered parameter policy update notification
What is an evpn switch?
Replication of variables in golang concurrency
MySQL cases MySQL find out who holds the row lock (RC)