From 980b896185f6856e8527847c8057a296278b1816 Mon Sep 17 00:00:00 2001 From: Yiu Tin Cheung Ivan Date: Wed, 12 Jul 2023 17:38:51 +0800 Subject: [PATCH] relation generation check SeaQL/sea-orm#1435 --- SeaORM/docs/0.12.x-CHANGELOG_temp.md | 2 +- SeaORM/docs/06-relation/03-many-to-many.md | 36 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/SeaORM/docs/0.12.x-CHANGELOG_temp.md b/SeaORM/docs/0.12.x-CHANGELOG_temp.md index 70787f7996f..cafeebad28c 100644 --- a/SeaORM/docs/0.12.x-CHANGELOG_temp.md +++ b/SeaORM/docs/0.12.x-CHANGELOG_temp.md @@ -363,7 +363,6 @@ pub enum StringValueVariant { _0x300x20123, } ``` - ================================ All Changes above was being Documented ================================ * [sea-orm-cli] The implementation of `Related` with `via` and `to` methods will not be generated if there exists multiple paths via an intermediate table. Like in the schema defined below - Path 1. `users <-> users_votes <-> bills`, Path 2. `users <-> users_saved_bills <-> bills` https://github.com/SeaQL/sea-orm/pull/1435 ```sql CREATE TABLE users @@ -397,6 +396,7 @@ CREATE TABLE users_saved_bills CONSTRAINT users_saved_bills_pkey PRIMARY KEY (user_id, bill_id) ); ``` + ================================ All Changes above was being Documented ================================ * [sea-orm-cli] fixed entity generation includes partitioned tables https://github.com/SeaQL/sea-orm/issues/1582, https://github.com/SeaQL/sea-schema/pull/105 * Fixed `ActiveEnum::db_type()` return type does not implement `ColumnTypeTrait` https://github.com/SeaQL/sea-orm/pull/1576 ```rs diff --git a/SeaORM/docs/06-relation/03-many-to-many.md b/SeaORM/docs/06-relation/03-many-to-many.md index df95ae640e8..e3670ae264a 100644 --- a/SeaORM/docs/06-relation/03-many-to-many.md +++ b/SeaORM/docs/06-relation/03-many-to-many.md @@ -89,3 +89,39 @@ pub enum Relation { Filling, } ``` + +Note that the implementation of `Related` with `via` and `to` methods will not be generated if there exists multiple paths via an intermediate table. + +For example, in the schema defined below - Path 1. `users <-> users_votes <-> bills`, Path 2. `users <-> users_saved_bills <-> bills` +```sql +CREATE TABLE users +( + id uuid PRIMARY KEY DEFAULT uuid_generate_v1mc(), + email TEXT UNIQUE NOT NULL, + ... +); +``` +```sql +CREATE TABLE bills +( + id uuid PRIMARY KEY DEFAULT uuid_generate_v1mc(), + ... +); +``` +```sql +CREATE TABLE users_votes +( + user_id uuid REFERENCES users (id) ON UPDATE CASCADE ON DELETE CASCADE, + bill_id uuid REFERENCES bills (id) ON UPDATE CASCADE ON DELETE CASCADE, + vote boolean NOT NULL, + CONSTRAINT users_bills_pkey PRIMARY KEY (user_id, bill_id) +); +``` +```sql +CREATE TABLE users_saved_bills +( + user_id uuid REFERENCES users (id) ON UPDATE CASCADE ON DELETE CASCADE, + bill_id uuid REFERENCES bills (id) ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT users_saved_bills_pkey PRIMARY KEY (user_id, bill_id) +); +``` \ No newline at end of file