Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upInner join, specify column #647
Comments
This comment has been minimized.
|
We don't currently support representing a join to the same two tables in different ways. Ultimately the plan for this is to allow giving a table an explicit alias, which you can reference separately. This gets into one of the fundamental impedence mismatches we have where you specify a join between to tables by annotating a random struct, not the table itself (because the table is likely not part of your code). Ultimately this is something that is not slated for 1.0, and very low on the priority list. What is on the priority list for 1.0 is to provide a better untyped raw SQL escape hatch for the "we don't support this" cases, so the answer to how to do this with Diesel will likely point you towards that API when added.
Yes, ultimately I want the While I do think this is something to support this eventually, since it's far past 1.0 and I don't have a concrete API in mind yet, I'm closing this as non-actionable. |
sgrif
closed this
Feb 8, 2017
This comment has been minimized.
Boscop
commented
Feb 8, 2017
|
I understand. let query = sql(&format!("select users.* from users join follows on id = sub_id where pub_id = {}", self.id));
query.get_results::<User>(&*database::connection().get().unwrap()).map_err(|e| e.into()) |
This comment has been minimized.
|
For the time being, yes -- only one of the two joins can be represented by the query builder |
This comment has been minimized.
Boscop
commented
Feb 8, 2017
|
Ok, but I get an error:
(It underlines
|
This comment has been minimized.
|
You need to specify the SQL type of the query when using the |
This comment has been minimized.
Boscop
commented
Feb 9, 2017
•
|
@sgrif Isn't that what I'm doing with let query = sql::<User>(&format!("select users.* from users join follows on id = sub_id where pub_id = {}", self.id));
query.get_results::<User>(&*database::connection().get().unwrap()).map_err(|e| e.into()) |
This comment has been minimized.
|
|
This comment has been minimized.
Boscop
commented
Feb 9, 2017
|
Thanks a lot, it works! |
Boscop commentedFeb 8, 2017
•
edited
Is it possible to specify the column to join on?
I want to find all followers of a user, the sql query would be:
It would be useful to have a way to specify which column to join on since I want to join on different columns in different cases, e.g. when getting the followees:
Also, sometimes there are other constraints than column equality in the join condition.
How can I express these two queries with diesel currently?