Closed
Description
- Version:
SQLBoiler v2.4.0
I have two models, User
and Investment
which are connected by a 1-many relationship.
When running the following code
boil.DebugMode = true
user, err := models.Users(
db,
qm.Where("email=?", email),
qm.Load("UserInvestments"),
).One()
if err != nil {
return err
}
if err := user.UserInvestments(db).DeleteAll(); err != nil {
return fmt.Errorf("failed to delete investments: %s", err)
}
it results in the following error
SELECT * FROM `Users` WHERE (email=?) LIMIT 1;
[me@gmail.com]
select * from `Investments` where `user_id` in (?)
[104]
DELETE FROM `Investments` as `a` WHERE (`a`.`user_id`=?);
[104]
failed to delete investments: models: unable to delete all from Investments: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as `a` WHERE (`a`.`user_id`=?)' at line 1
When I change the delete line to
if err := models.Investments(db, qm.Where("user_id=?", user.ID)).DeleteAll(); err != nil {
all passes with this output
SELECT * FROM `Users` WHERE (email=?) LIMIT 1;
[me@gmail.com]
select * from `Investments` where `user_id` in (?)
[104]
DELETE FROM `Investments` WHERE (user_id=?);
[104]
Metadata
Metadata
Assignees
Labels
No labels