gorm find函数里设置的筛选条件怎么样才能不影响joins
如果你想在GORM的find函数中设置筛选条件而不影响joins,可以将条件放在where函数中而不是在find函数中。例如:
db.Joins("LEFT JOIN orders ON orders.user_id = users.id").
Where("users.name = ?", "John").
Find(&users)
这将会执行一个LEFT JOIN并筛选出名为"John"的用户,而不影响joins。
原文地址: https://www.cveoy.top/t/topic/bnyo 著作权归作者所有。请勿转载和采集!