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

Multiple joins between two tables are not possible #332

Closed
weiznich opened this Issue May 18, 2016 · 2 comments

Comments

Projects
None yet
3 participants
@weiznich
Contributor

weiznich commented May 18, 2016

Given the following two tables:

CREATE TABLE points(
        id BIGSERIAL PRIMARY KEY,
        x DOUBLE PRECISION NOT NULL,
        y DOUBLE PRECISION NOT NULL);

and

CREATE TABLE boxes(
        id BIGSERIAL PRIMARY KEY,
        o BIGINT REFERENCES points(id) NOT NULL,
        u BIGINT REFERENCES points(id) NOT NULL);

I want both relations to be joinable.

infer_table_from_schema!(dotenv!("DATABASE_URL"), "points");
infer_table_from_schema!(dotenv!("DATABASE_URL"), "boxes");

joinable!(boxes -> points (o));
joinable!(boxes -> points (u));

This is currently not possible because the joinable macro is generating a conflicting implementation of the trait JoinTo.

error: conflicting implementations of trait `diesel::JoinTo<points::table, _>` for type `boxes::table`: [--explain E0119]
 --> <diesel macros>:4:1
4 |> impl < JoinType > $ crate :: JoinTo < $ right_table , JoinType > for $
  |> ^

@bpbp-boop

This comment has been minimized.

bpbp-boop commented Oct 10, 2017

I just ran into this

table! {
    matches (id) {
        id -> Integer,
        date -> Nullable<Date>,
        time -> Nullable<Time>,
        home_team_id -> Nullable<Integer>,
        away_team_id -> Nullable<Integer>,
    }
}

table! {
    teams (id) {
        id -> Integer,
        name -> Text,
    }
}

joinable!(matches -> teams (home_team_id));
joinable!(matches -> teams (away_team_id));

Have any workaround surfaced since this was opened?

@sgrif

This comment has been minimized.

Member

sgrif commented Oct 10, 2017

This is the expected behavior. Otherwise we have no clue what you mean when you say matches.inner_join(teams). You can use the .on method to specify an explicit on clause.

@sgrif sgrif closed this Oct 10, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment