var friends []*models.Friend
if res := f.db().Debug().Model(&models.Friend{}).Where(&models.Friend{UserA: userID}).Or(models.Friend{UserB: userID}).Find(&friends); res.Error != nil {
logger.Error(res.Error)
return nil, queryErr
}
The code above executes the SQL as follows:
SELECT * FROM `friends` WHERE `friends`.`user_a` = 1 OR `friends`.`user_b` = 1 AND `friends`.`deleted_at` IS NULL
which obviously has priority issues. Although it could be easily avoided, IMO most use cases here are intended as "(XX OR XX) AND deleted_at IS NULL", otherwise the Or() API is less useful and will cause unintentional mistakes.
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
`friends`.`user_a` = 1 OR `friends`.`user_b` = 1 AND `friends`.`deleted_at` IS NULL
equals
(`friends`.`user_a` = 1 OR `friends`.`user_b` = 1) AND `friends`.`deleted_at` IS NULL
`friends`.`user_a` = 1 OR `friends`.`user_b` = 1 AND `friends`.`deleted_at` IS NULLequals
(`friends`.`user_a` = 1 OR `friends`.`user_b` = 1) AND `friends`.`deleted_at` IS NULL
No, it does't.
Hi @voe1999
Sorry for the issue, there was an issue when using soft delete with or conditions, just pushed a commit to fix the issue.
Thank you for your report.