Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate entity for duplicated many-to-many paths #1435

Merged
merged 2 commits into from
Apr 13, 2023

Conversation

billy1624
Copy link
Member

@billy1624 billy1624 commented Jan 30, 2023

PR Info

Bug Fixes

  • The implementation of Related<R> 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
CREATE TABLE users
(
  id uuid  PRIMARY KEY  DEFAULT uuid_generate_v1mc(),
  email TEXT UNIQUE NOT NULL,
  ...
);
CREATE TABLE bills
(
  id uuid  PRIMARY KEY  DEFAULT uuid_generate_v1mc(),
  ...
);
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)
);
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)
);

Adapted from #1333 (comment)

@billy1624 billy1624 self-assigned this Jan 30, 2023
@billy1624 billy1624 force-pushed the gen-entity-duplicated-many-to-many-paths branch from fd58b72 to 372484d Compare January 30, 2023 10:09
@billy1624 billy1624 added this to the 0.11.x milestone Jan 30, 2023
@billy1624 billy1624 marked this pull request as ready for review January 30, 2023 10:39
@billy1624 billy1624 requested a review from tyt2y3 January 30, 2023 10:39
Comment on lines +259 to +261
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
components: rustfmt
- run: cargo fmt --manifest-path ${{ matrix.path }} --all -- --check
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are these bits about though

Copy link
Member Author

@billy1624 billy1624 Jan 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Install nightly channel with rustfmt component. Then, run cargo +nightly fmt

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only night's fmt respect rustfmt.toml config file that's why.

@billy1624
Copy link
Member Author

This PR includes a written-entity to generated-entity test cases. Which works like this:

  1. sea-orm is being added as dev-dependency on the codegen crate. All entity files under codegen/tests_cfg module are being compiled and checked.
  2. The tests were performed at the end of transformer.rs. Using create_table_from_entity to generate SeaQuery create table statement from the SeaORM entity.
  3. Then, the statement was passed to EntityTransformer and followed by EntityWriter::gen_compact_code_blocks.
  4. Finally, assert the output from the writer againsts the file defined in codegen/tests_cfg

@tyt2y3
Copy link
Member

tyt2y3 commented Jan 30, 2023

This is a very substantial change and seems to only fix a special case. Can we postpone this?

@billy1624
Copy link
Member Author

Okay, we can ship this with 0.11.1 and backport this to 0.10.x

Shall we?

@billy1624 billy1624 removed this from the 0.11.x milestone Jan 30, 2023
@tyt2y3
Copy link
Member

tyt2y3 commented Jan 31, 2023

No. I mean, to postpone it after 0.11

@kev0960
Copy link
Contributor

kev0960 commented Feb 23, 2023

Just curious when this can be merged? It's the only blocker that we cannot upgrade to a newer version

@tyt2y3
Copy link
Member

tyt2y3 commented Feb 23, 2023

Even if this gets merged now there will still be some time before the next release.
I can rebase the branch onto master, so you can install it and try it out locally.

@tyt2y3 tyt2y3 force-pushed the gen-entity-duplicated-many-to-many-paths branch from 5a174b8 to fbe8968 Compare February 23, 2023 13:27
@billy1624 billy1624 merged commit 2c08255 into master Apr 13, 2023
@billy1624 billy1624 deleted the gen-entity-duplicated-many-to-many-paths branch April 13, 2023 03:16
darkmmon added a commit to darkmmon/seaql.github.io that referenced this pull request Jul 12, 2023
billy1624 added a commit to SeaQL/seaql.github.io that referenced this pull request Jul 19, 2023
* Optional Field SeaQL/sea-orm#1513

* .gitignore SeaQL/sea-orm#1334

* migration table custom name SeaQL/sea-orm#1511

* OR condition relation SeaQL/sea-orm#1433

* DerivePartialModel SeaQL/sea-orm#1597

* space for migration file naming SeaQL/sea-orm#1570

* composite key up to 12 SeaQL/sea-orm#1508

* seaography integration SeaQL/sea-orm#1599

* QuerySelect SimpleExpr SeaQL/sea-orm#1702

* sqlErr SeaQL/sea-orm#1707

* migration check SeaQL/sea-orm#1519

* postgres array SeaQL/sea-orm#1565

* param intoString SeaQL/sea-orm#1439

* **skipped** re-export SeaQL/sea-orm#1661

* ping SeaQL/sea-orm#1627

* on empty do nothing SeaQL/sea-orm#1708

* on conflict do nothing SeaQL/sea-orm#1712

* **skipped** upgrade versions

* active enum fail safe SeaQL/sea-orm#1374

* relation generation check SeaQL/sea-orm#1435

* entity generation bug SeaQL/sea-schema#105

* **skipped** bug fix that does not require edits

* EnumIter change SeaQL/sea-orm#1535

* completed and fixed a previous todo SeaQL/sea-orm#1570

* amended wordings and structures

* Edit

* Remove temp file

---------

Co-authored-by: Billy Chan <ccw.billy.123@gmail.com>
@github-actions
Copy link

github-actions bot commented Aug 2, 2023

🎉 Released In 0.12.1 🎉

Thank you everyone for the contribution!
This feature is now available in the latest release. Now is a good time to upgrade!
Your participation is what makes us unique; your adoption is what drives us forward.
You can support SeaQL 🌊 by starring our repos, sharing our libraries and becoming a sponsor ⭐.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

0.10.6: still issues with conflicting implementations of trait
3 participants