-
Notifications
You must be signed in to change notification settings - Fork 1.4k
One to Many (1:N) clarification #856
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
Comments
Shouldn't it be |
What I've Tried let consumable_or_error = query_as!(
Consumable,
r#"
SELECT
c.*,
(
s.id,
s.consumable_id,
s.amount,
s.kcal,
) AS "servings: Vec<Serving>"
FROM consumable AS c
LEFT OUTER JOIN serving AS s
ON c.id = s.consumable_id
WHERE id = $1
"#,
id
)
.fetch_one(pool.get_ref())
.await; but I still get compilation errors. From #298 , I'm not even sure if what I'm asking is possible but I'm pretty much stuck wither way. |
@flopshot any update on this? I have the same issues. seems the nested struct is not supporting even I use the sqlx::type
Thanks a lot for the help. |
@jayhuang75 No I haven’t. Honestly, I gave up on this library as being too complicated for 1:Many relationships. And if you have something like 1:Many:Many relationships, forget it. Just use Diesel. It is way more user friendly and has better documentation and blog posts. If you need to use it with async concurrency, follow this |
SQLx is a SQL library. We will not attempt to generate SQL and do not currently have a clean way to assist with these kinds of queries. You should make them the same you would in any raw SQL library.
I'm going to close this only because we aren't planning to provide any kind of assistance here directly. @flopshot @jayhuang75 Please look at https://docs.rs/ormx/0.2.0/ormx/ though for where this kind of functionality could be added. |
@flopshot your original error there is because you have an error in your SQL, you can't have a
|
I appreciate the response @mehcode. |
Hello. Don't mean to bother for clarification, but I can't seem to find a straight forward answer about sqlx support for One to Many deserialization.
I have a one to many relation between two tables:
And these are the corresponding structs
Is there a way to write a query with
query_as!
that will directly write to an instance ofConsumable
Something like this
Is this possible with sqlx or would I just have to query the tables separately and
compose the structs in rust?
The text was updated successfully, but these errors were encountered: