-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Note join extract struct not supported #2627
Conversation
As we do exactly that what you describe as impossible as part of our test suite I would rather not like to have this sentence in our documentation (as this is actually possible and supported.) |
Oh, weird maybe because I was doing multiple joins that it make it not working? I guess I will close it and reinvestigate. |
Ah, I think it is because the table! {
comments (id) {
id -> Integer,
body -> Text,
post_id -> Integer,
user_id -> Integer,
}
}
table! {
posts (id) {
id -> Integer,
title -> Text,
body -> Nullable<Text>,
user_id -> Integer,
}
}
allow_tables_to_appear_in_same_query!(
comments,
posts,
users,
);
joinable!(comments -> users (user_id));
#[derive(Queryable, Debug)]
pub struct Post {
pub id: i32,
pub title: String,
pub body: Option<String>,
pub user_id: i32,
}
#[derive(Queryable, Debug)]
pub struct Comment {
pub id: i32,
pub body: String,
}
fn main() {
...
let query = comments.inner_join(posts);
let data: Vec<(Comment, Post)> = query.load(&conn).unwrap();
} The error.
I believe it's because the If you want I can provide a reproducible case. |
@pickfire I'm not sure why you find that surprising. That's the normal behaviour of |
Oh, I wasn't aware of this. Quite a surprise to me, I tried it without join it also didn't work. I did a quite search in the docs https://docs.rs/diesel/1.4.5/diesel/deserialize/trait.Queryable.html
It only mentions that field order is important. And this
Now I am confused. It says it does not necessary mean they represent a single database table. Is there a way to join but extract only part of it from the table? IIRC we can query part of the data right? |
@pickfire First of all: This is not really the right place for this discussion. Please use the gitter channel for such questions.
If it's a 1:1 mapping it implies that it cannot skip fields in my opinion.
Yes there is. See the documentation on |
Sorry, I have no more questions.
Queryable documentation does not make it clear that it is a one-to-one mapping. |
Again this is the behaviour of
It clearly says that the fields must match in order, which implies that there must be the same number of fields. If you have suggestions how to improve this formulation while not exclude use cases that have a custom setup somewhere feel free to submit a PR. The documentation for the upcoming 2.0 release has even an example which code is generated. |
IMHO, no, doesn't imply |
@Mingun If you believe that feel free to submit a PR to improve that wording. Otherwise: I do not really like people coming up again and again criticizing (fundamental) things without providing any justification and without contributing otherwise to the project. Either start contributing something or add something actionable to your comments or stop making them as they are currently not helpful for any of the contributors. |
As I saw
(User, (Post, Comment))
in the docs, I thought using join to extract the original struct out without usingselect
works, I spent some time trying it out and I believe it does not work. It would be better to tell others thatselect
is still needed without letting them try it since it will fail during compilation time.Or maybe we can explain this is due to ambiguity?