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

Many-To-Many Joins #398

Closed
Necoro opened this Issue Aug 8, 2016 · 6 comments

Comments

Projects
None yet
6 participants
@Necoro

Necoro commented Aug 8, 2016

Currently it seems to not be possible to use many-to-many joins in diesel. I was unable to find some out-of-the-box "many-to-many from A to B via cross-table C" -- and for manual implementation (one-to-many from A to C, many-to-one from C to B) support for id-less tables (C obiously has a compound PK) is missing.

Thus, I wanted to open this issue as a reminder (I'm quite astonished that there is none yet :))

@sgrif

This comment has been minimized.

Member

sgrif commented Aug 8, 2016

Thanks for the issue! This pretty much falls naturally out of the current design once we add composite PK support in general, which is something I'm working on.

@cbrewster

This comment has been minimized.

cbrewster commented Dec 27, 2016

Hi @sgrif, is there anywhere where I can track the progress of composite PK support?

@killercup

This comment has been minimized.

Member

killercup commented Dec 27, 2016

@cbrewster

This comment has been minimized.

cbrewster commented Dec 27, 2016

@killercup awesome! Is there a recommended way to handle many-to-many yet or is that still in the works?

@lholden

This comment has been minimized.

lholden commented Jan 4, 2017

@cbrewster @killercup The composite stuff works... but many to many stuff is still messy by the looks of it.
An example of specifying a composite key in the table! macro:

table! {
    firsts_seconds (first_id, second_id) {
        first_id -> Integer,
        second_id -> Integer,
    }
}

And then I guess you can do a join query on the firsts_seconds and seconds where the first_id matches the id of the first you are starting with.

jnferner added a commit to jnferner/homepage that referenced this issue Mar 31, 2017

DB: Remove composit primary key
Diesel still struggles with this
diesel-rs/diesel#398
@Kerollmops

This comment has been minimized.

Contributor

Kerollmops commented Apr 10, 2017

Hi everybody !

Is there some news on many-to-many joins ?
I noticed that infer_schema! only supports tables with primary keys and that's not mandatory for many-to-many joins.

Therefore I don't know how to represent simple tables joins between Users and Teams (for example).

Thanks ❤️

EDIT: Ooops! It seems the table! macro can help me...

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