Skip to content

Proper way to do many-to-many? #4404

Answered by weiznich
duckfromdiscord asked this question in Q&A
Discussion options

You must be logged in to vote

I'm currently on mobile, so I cannot easily test this on my own.

What I can say from looking at the query you wrote is:

  • That's likely already a goof starting point
  • Your SQL query uses aliases, your DSL query don't. You likely need these aliases to correctly refer to the right table instance. Have a look at diesel::alias! for that.
  • For the sub query you seem to use diesel::select which constructs a select query without from clause, therefore the first error message. You want to use a normal query construct there as well.
  • You likely need to call .single_value() on the subquery to turn into an expression that can be used as right hand side of .eq()
  • Finally subqueries are assumed to be nulla…

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@weiznich
Comment options

@duckfromdiscord
Comment options

@weiznich
Comment options

Answer selected by duckfromdiscord
@duckfromdiscord
Comment options

@duckfromdiscord
Comment options

@weiznich
Comment options

@duckfromdiscord
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants