Is it possible to chain Joins? As I try Joins().Joins() it generates query with last join. What should I do if I need 2 joins and for each of them I need where condition?
You could only write one big Joins conditions for now, like:
db.Joins("left joins xxx on 2=2 left joins yyy on 1=1").Find(&users)
This would be very useful to build up a query with different joins depending on program logic
This would be a useful to have this!
Also, a heads up, the documentation is misleading about this. Under Query at the end in the Joins section it mentions:
// multiple joins with parameter
db.Joins("JOIN emails ON emails.user_id = users.id AND emails.email = ?", "[email protected]").Joins("JOIN credit_cards ON credit_cards.user_id = users.id").Where("credit_cards.number = ?", "411111111111").Find(&user)
Most helpful comment
Also, a heads up, the documentation is misleading about this. Under Query at the end in the Joins section it mentions: