Hi! How can I write conditions for Joins? I need something like this
Joins("UserProgram", "currency_id = ? AND activated IS NOT NULL AND finished IS NULL AND error IS NULL", currencyID)
But it wont work, this type of conditions works only with Preload. And I do not want to write whole table names and stuff, like
Joins("promo_usergrogram on promo_userprogram.user_program_id = ...").Where("promo_usergrogram.currency_id = ? ...")
In documentation we have
db.Joins("Company", DB.Where(&Company{Alive: true})).Find(&users)
But how can I use it for condition like
activated (time type) IS NOT NULL AND finished(time type) IS NULL AND error (string type) IS NULL
The document you expected this should be explained
https://gorm.io
Comment From: samadguliev
I found a different way for condition db.Joins("Company").Where(`"Company"."alive" = ?`, true).Find(&users)
Comment From: wxy2077
maybe you can do this
db.Preload("Company", func(tx *gorm.DB) *gorm.DB {
return tx.where("alive = ?", true)
})
Comment From: samadguliev
@wxy2077 yeah but i need Where conditions for Joins
Comment From: zuzuviewer
How can I write conditions for InnerJoins, above solutions aren't work
Comment From: samadguliev
@zuzuviewer I don't know about InnerJoins, but this worked for Joins https://github.com/go-gorm/gorm/issues/6842#issuecomment-1958877615
Comment From: zuzuviewer
@zuzuviewer I don't know about InnerJoins, but this worked for Joins #6842 (comment)
I have tried it with 1.25.5. It didn't work and not in join condition
Comment From: zuzuviewer
I found a way to resolve: `tx := db.Table("user")
tx.InnerJoin("Company",db.Table("company").Where("id = ?",id))`