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 upDocumentation for multi-table inner join is confusing #1129
Comments
This comment has been minimized.
|
Thanks for great issue! You don't see a repro repo every day :)
…and I'm make sure to actually look at that later (
… Am 25.08.2017 um 17:51 schrieb Carol (Nichols || Goulding) ***@***.***>:
Setup
I have a repo demonstrating this problem here: https://github.com/carols10cents/diesel-inner-join-mvce
Versions
• Rust: stable 1.19.0
• Diesel: 0.16.0
• Database: postgres 9.6.1
• Operating System macOS Sierra
Feature Flags
• diesel: postgres
• diesel_codegen: postgres
Problem Description
What are you trying to accomplish?
I have these tables:
#[derive(Debug, Clone, Queryable, Identifiable, Associations, AsChangeset)]
pub struct Crate {
pub id: i32,
pub name: String,
}
#[derive(Clone, Identifiable, Queryable, Associations, Debug)]
#[belongs_to(Crate)]
pub struct Version {
pub id: i32,
pub crate_id: i32,
}
#[derive(Insertable, Identifiable, Queryable, Associations, Debug)]
#[belongs_to(Version)]
#[table_name = "readme_rendering"]
#[primary_key(version_id)]
struct ReadmeRendering {
version_id: i32,
rendered_at: String,
}
And I would like to write diesel that generates the equivalent of:
SELECT * FROM versions
INNER JOIN readme_rendering ON versions.id = readme_rendering.version_id
INNER JOIN crates on versions.crate_id = crates.id;
This looks similar to the example with users, posts, and comments in the docs that says users.inner_join(posts).inner_join(comments) generates this sql:
SELECT * FROM users
INNER JOIN posts ON posts.user_id = users.id
INNER JOIN comments ON comments.user_id = users.id
So I have this query:
let versions_to_readme_and_crates_doesnt_work = versions::table
.inner_join(readme_rendering::table)
.inner_join(crates::table)
.select((versions::all_columns, readme_rendering::rendered_at, crates::name))
.load::<(Version, Option<String>, Option<String>)>(&conn)
.expect("error loading versions_to_readme_and_crates_doesnt_work");
What is the expected output?
I expect this to compile and run the sql above.
What is the actual output?
I get this compilation error, which seems to indicate diesel is trying to join crates and readme_rendering?
error[E0277]: the trait bound `__diesel_infer_schema::infer_readme_rendering::readme_rendering::table: diesel::JoinTo<__diesel_infer_schema::infer_crates::crates::table>` is not satisfied
--> src/main.rs:62:10
|
62 | .inner_join(crates::table)
| ^^^^^^^^^^ the trait `diesel::JoinTo<__diesel_infer_schema::infer_crates::crates::table>` is not implemented for `__diesel_infer_schema::infer_readme_rendering::readme_rendering::table`
Full errors behind toggle:
Are you seeing any additional errors?
Nope. There's other code in the repo that shows versions joining to crates works fine, and versions joining to readme_rendering works fine.
Steps to reproduce
Clone https://github.com/carols10cents/diesel-inner-join-mvce and cargo run; you should get the errors shown above.
Checklist
• I have already looked over the issue tracker for similar issues.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
This comment has been minimized.
|
Hey, thanks for the awesome bug report with a repository and everything You need to add a |
This comment has been minimized.
|
Ha! Forget everything I said and only believe Bastien from now on.
… Am 25.08.2017 um 18:06 schrieb Bastien Orivel ***@***.***>:
Hey, thanks for the awesome bug report with a repository and everything
|
This comment has been minimized.
carols10cents
commented
Aug 25, 2017
You're welcome! I try :)
I read the docs for that, but I didn't think that applied because i'm not trying to do crates.inner_join(readme_rendering) at all :-/ Why do I need that if I'm only trying to join each of those to version but not to each other?
but that's not the join i'm trying to do, i'm trying to do the equivalent of |
This comment has been minimized.
carols10cents
commented
Aug 25, 2017
|
Ok, I just tried it and the code compiles and runs the query i'm expecting... I think this is a documentation bug then :) The comment on the |
carols10cents
changed the title from
Multi-table inner join not functioning as expected given documentation
to
Documentation for multi-table inner join is confusing
Aug 25, 2017
killercup
added
bug
documentation
labels
Aug 25, 2017
This comment has been minimized.
krircc
commented
Aug 29, 2017
|
I have the same problme, when i do with inner_join |
carols10cents commentedAug 25, 2017
•
edited
Setup
I have a repo demonstrating this problem here: https://github.com/carols10cents/diesel-inner-join-mvce
Versions
Feature Flags
Problem Description
What are you trying to accomplish?
I have these tables:
And I would like to write diesel that generates the equivalent of:
This looks similar to the example with users, posts, and comments in the docs that says
users.inner_join(posts).inner_join(comments)generates this sql:So I have this query:
What is the expected output?
I expect this to compile and run the sql above.
What is the actual output?
I get this compilation error, which seems to indicate diesel is trying to join crates and readme_rendering?
Full errors behind toggle:
Are you seeing any additional errors?
Nope. There's other code in the repo that shows versions joining to crates works fine, and versions joining to readme_rendering works fine.
Steps to reproduce
Clone https://github.com/carols10cents/diesel-inner-join-mvce and
cargo run; you should get the errors shown above.Checklist