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 upAllow update/delete with joined tables #1478
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
csirkeee commentedJan 14, 2018
•
edited
The missing feature
Right now Diesel doesn't allow for update/delete with joined tables. This seems like an explicit decision based on having
Which means the update target must be a query that only touches one table.
But, using multiple tables in update/delete is a feature that both MySQL and Postgres support. (I didn't research the other databases.) So, it would be nice if Diesel could also support it. In this feature request I'll describe how that could look like.
Example code
Update
For example, working with the tables in the test suite, this could be a valid query:
This would translate to the following query in MySQL:
And into this query on Postgres:
Delete
Delete is a similar case:
could translate, in MySQL, to:
and in Postgres:
(I've checked all SQL to be valid on SQLFiddle.)
Implementation
The main problem with the implementation is that the query builder would need to handle join clauses differently from other filters. Also, the syntax is different for the databases, I don't know how much that complicates things. (It's possible that there exists a syntax that both MySQL and Postgres accept, but I haven't found one.)
Maybe the first part could be handled by using a different syntax in rust, like calling the joins on the
updatequery and not on the table, like this: