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

Represent several relations between same types #89

Closed
nicoulaj opened this issue Aug 16, 2021 · 3 comments · Fixed by #104
Closed

Represent several relations between same types #89

nicoulaj opened this issue Aug 16, 2021 · 3 comments · Fixed by #104
Assignees

Comments

@nicoulaj
Copy link

nicoulaj commented Aug 16, 2021

Example problematic cases:

  1. Entities A et B have several different many-to-many relations
  2. Entity A has several one-to-many relations to entity B (Eg: COUPLE.member1 -> USER and COUPLE.member2 -> USER)

In these cases there are several issues:

  1. the codegen uses A/B entity names to generate Relation variants, so we obtain duplicate variants. I guess it could use the join table or foreign key entity name
  2. the Related trait is typed on A/B entities, so same issue. So I believe fixing this requires a breaking conception change...
@tyt2y3
Copy link
Member

tyt2y3 commented Aug 16, 2021

Related was not designed to support this scenario and I want to keep its current definition for its simplicity of usage.

Goods news is, we had thought about how to define advanced relations with more than two level joins, and it would be another triat concept. Perhaps something like:

trait Linked {
    type FromEntity: EntityTrait;
    type ToEntity: EntityTrait;
    fn link(&self) -> Vec<RelationDef>;
}

such that multiple Link could be defined between any pair of Entities.

@tyt2y3 tyt2y3 added this to the 0.2.0 milestone Aug 16, 2021
@tyt2y3
Copy link
Member

tyt2y3 commented Aug 17, 2021

Some clarifications:

Related is for inherit relations, like order with order item and product with product attribute, basically an edge on the ER diagram.

While Linked is the connection between any two Entity on the ERD, which can jump through multiple hops, and have multiple valid routes.

@tyt2y3
Copy link
Member

tyt2y3 commented Aug 22, 2021

We target to introduce new APIs in 0.2.0
Meanwhile you can use the 'unbounded' join method (like in https://www.sea-ql.org/SeaORM/docs/advanced-query/more-join)

@tyt2y3 tyt2y3 changed the title Cannot represent several relations between same types Represent several relations between same types Aug 22, 2021
billy1624 added a commit that referenced this issue Aug 23, 2021
@billy1624 billy1624 self-assigned this Aug 23, 2021
@billy1624 billy1624 mentioned this issue Aug 28, 2021
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants