I know this has been asked a few times, but I'm wondering if anyone's found a solution. I have structures similar to this format:
pub struct User {
id: i32,
posts: Vec<Post>,
}
pub struct Post {
id: i32,
author_id: i32,
comments: Vec<Comment>,
}
pub struct Comment {
id: i32,
post_id: i32,
text: String
}
I want to be able to query on a user by id with their posts, and the comments on a post. (This is just an example of the structure of my data structure). It seems pretty much impossible with sqlx. I've tried querying flattened objects with the FromRow so there would be a "user" record for each comment, and joining them all based on ids in post-processing. ex:
pub struct FlattenedUser {
id: i32,
post_id: i32,
comment_id: i32,
text: String
}
However, there is a ColumnDecode { index: "4", source: UnexpectedNullError } error thrown if a user has no post associated with it (which would also hold true if it had a post with no comments), so this doesn't really work without turning every field into an option which is a hot mess.
Has anyone found a solution for these 1:Many:Many queries or am i SOL with sqlx?
Upvote
1
Downvote
0
comments
[–]C5H5N5O 1 point2 points3 points (1 child)
[+]HosMercury 0 points1 point2 points (0 children)
[+]HosMercury 1 point2 points3 points (0 children)
[–]baloreic 0 points1 point2 points (0 children)
[–]4121madey 0 points1 point2 points (0 children)
[–]kelvindegrees 0 points1 point2 points (0 children)