var languages1 []Language
emptyQueryConds := []string{}
err := DB.Find(&languages1, emptyQueryConds).Error
When use Db.find(&models, queryConds) , if queryConds is empty will query all records, but i think than should return empty result, but now it's same as Db.find(&models) . That are so different
playground : https://github.com/go-gorm/playground/pull/470
Comment From: a631807682
https://gorm.io/docs/query.html#Inline-Condition
Query conditions can be inlined into methods like First and Find in a similar way to Where. 1. If
whereclause is empty, it should query all records. 2. You should not query the database if you do not need data when thequeryCondsis empty.
Comment From: Heliner
1.that is the problem, when use
// test in sqllite
// not empty conds
DB.Where(" id in ?", notEmptyConds).Find(&results) // 1.1 get sql: select * from xxx where id in (notEmptyConds[0], .... );
DB.Find(&results, notEmptyConds) // 1.2. get sql: select * from xxx where id in (notEmptyConds[0], .... );
// emty conds
DB.Where(" id in ?", emptyConds).Find(&results) // 2.1 get sql: select * from xxx in (NULL); //result is None
DB.Find(&results, emptyConds) // 2.2 get sql : select * from xxx ; //result is all table records
If the Find() is really is an Query conditions can be inlined into methods like First and Find in a similar way to Where. , why 2.1 and 2.2 will get different sql and result ? so, I still think that is an semantic error of Find(), when `FInd(&results, emptyConds) ,the results should be emtpy same as Where("id in ?", emptyConds).Find(&results)。I'm not sure if I've made this clear in English
Comment From: holicc
if so, how does the sql look like ?
DB.Find(&results, emptyConds) could be like select * from xxx where NULL or select * from xxx where in (NULL) ?