sqlboiler
sqlboiler copied to clipboard
`DeleteAll` finisher ignores the inner join query mod
What version of SQLBoiler are you using (sqlboiler --version
)?
After #702 : 3.7.0
What is your database and version (eg. Postgresql 10)
MySQL 8.0.19
If this happened at runtime what code produced the issue? (if not applicable leave blank)
models: unable to delete all from pilots: Error 1054: Unknown column 'jets.pilot_id' in 'where clause
Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)
I used the example database schema to reproduce.
Further information. What did you do, what did you expect?
What I did
// Should have something like:
// DELETE `pilots` FROM `pilots`
// INNER JOIN `jets`
// WHERE `jets`.`pilot_id`=`pilots`.`id` AND (`pilots`.`name`=?)
nbdel, pilotE := models.Pilots(
qm.InnerJoin(models.TableNames.Jets),
qm.Where(
models.TableNames.Jets + "." + models.JetColumns.PilotID + "=" +
models.TableNames.Pilots + "." + models.PilotColumns.ID,
),
qm.Expr(
models.PilotWhere.Name.EQ(pilotName),
),
).DeleteAll(context.Background(), globalDB)
Debug output (boil.DebugMode = true
):
DELETE FROM `pilots` WHERE jets.pilot_id=pilots.id AND (`pilots`.`name` = ?);
[John1524367192]
- The above code ignore the INNER JOIN. I expected it to be present.
- There is should be "
pilots
" before the FROM otherwise there would be a syntax error when adding the INNER JOIN.
I know the above query does not make a lot of sense. But the inner join in a delete have use cases: "Delete all pilots which have a common jet with the pilot currently being deleted"
This seems to be a mysql-specific feature request. Looking at postgres' delete syntax it has a different way of pulling in other columns.
Probably not going to do this as it lacks utility for postgresql. Though any non-breaking pull-request to fix this would probably not be turned down if it wasn't crazy :D
https://www.postgresql.org/docs/12/sql-delete.html