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

0.10.6: still issues with conflicting implementations of trait #1333

Closed
frederikhors opened this issue Dec 23, 2022 · 9 comments · Fixed by #1435
Closed

0.10.6: still issues with conflicting implementations of trait #1333

frederikhors opened this issue Dec 23, 2022 · 9 comments · Fixed by #1435
Assignees

Comments

@frederikhors
Copy link
Contributor

frederikhors commented Dec 23, 2022

Since #1287 is closed I just tried 0.10.6: unfortunately the issue is still there:

impl Related<super::tenant::Entity> for Entity {
    fn to() -> RelationDef {
        super::house::Relation::Tenant.def()
    }
    fn via() -> Option<RelationDef> {
        Some(super::house::Relation::Player.def().rev())
    }
}

impl Related<super::tenant::Entity> for Entity {
    fn to() -> RelationDef {
        super::offer::Relation::Tenant.def()
    }
    fn via() -> Option<RelationDef> {
        Some(super::offer::Relation::Player.def().rev())
    }
}

with error:

error[E0119]: conflicting implementations of trait `sea_orm::Related<generated::tenant::Entity>` for type `generated::player::Entity`
  --> src\entities\player.rs:65:1
   |
56 | impl Related<super::tenant::Entity> for Entity {
   | ---------------------------------------------- first implementation here
...
65 | impl Related<super::tenant::Entity> for Entity {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `generated::player::Entity`

error[E0119]: conflicting implementations of trait `sea_orm::Related<generated::player::Entity>` for type `generated::tenant::Entity`
   --> src\entities\tenant.rs:135:1
    |
117 | impl Related<super::player::Entity> for Entity {
    | ------------------------------------------------ first implementation here
...
135 | impl Related<super::player::Entity> for Entity {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `generated::tenant::Entity`

The entities in this case are:

Player {
    pub tenant_id: String,
}

House {
    pub tenant_id: String,
    pub player_id: String,
}

Offer {
    pub tenant_id: String,
    pub player_id: String,
}

I'll downgrade to 0.10.2 for now.

On other entites there is the same issue too (because of tenant_id).

@billy1624 billy1624 self-assigned this Jan 21, 2023
@billy1624
Copy link
Member

Hey @frederikhors, sorry for the delay. I was not able to reproduce the error. Could you please provide a sample SQL like below?

create table if not exists player
(
    id integer
);

create unique index if not exists player_id_uindex
    on player (id);

create table if not exists tenant
(
    id integer
);

create unique index if not exists tenant_id_uindex
    on tenant (id);

create table if not exists house
(
    tenant_id integer
        constraint house_tenant_id_fk
            references tenant (id),
    player_id integer
        constraint house_player_id_fk
            references player (id)
);

create table if not exists offer
(
    tenant_id integer
        constraint offer_tenant_id_fk
            references tenant (id),
    player_id integer
        constraint offer_player_id_fk
            references player (id)
);

image

@billy1624 billy1624 moved this from Triage to In Progress in SeaQL Dev Tracker Jan 21, 2023
@frederikhors
Copy link
Contributor Author

I'll in a few hours. Sorry for the delay.

@billy1624
Copy link
Member

Thanks!! @frederikhors No rush!

@ryanoillataguerre
Copy link

ryanoillataguerre commented Jan 29, 2023

+1 to this, blocking my migration to sea-orm at the moment :/

These are with freshly generated entity files from sea-orm-cli and two many-to-many tables, users_saved_bills, and users_votes

Screenshot 2023-01-29 at 2 30 53 PM

Screenshot 2023-01-29 at 2 30 30 PM

Screenshot 2023-01-29 at 2 31 54 PM

@frederikhors
Copy link
Contributor Author

@ryanoillataguerre, can you post your sql? I cannot right now since I switched project.

@ryanoillataguerre
Copy link

ryanoillataguerre commented Jan 29, 2023

Hey @frederikhors no problem, here it is below:

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)
);

@ryanoillataguerre
Copy link

Is there another way to define these many to manies that I'm not catching in my SQL?

@billy1624
Copy link
Member

Thanks everyone for the help!! Please check this PR

@ryanoillataguerre
Copy link

Thanks everyone for the help!! Please check this PR

This is awesome, thanks @billy1624 ! Hope it gets merged soon.

Out of curiosity, does this problem only show up for non-sea-orm migration-defined tables? Like if I were to rewrite my migrations in Rust how the Getting Started guide does it, would this conflict not happen?

@github-project-automation github-project-automation bot moved this from In Progress to Done in SeaQL Dev Tracker Apr 13, 2023
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 a pull request may close this issue.

3 participants