Assocation not working with Where function

Viewed 47

guys I am trying to get records using the Association function using gorm but it's not working and ain't giving an output

I have same problem when giving Where condition using the Association function


type User struct {
    gorm.Model
    Name   string
    Orders []Order
}

type Order struct {
    gorm.Model
    Product string
    UserId  uint
}

func main() {
........
    var orders []Order
    var user User
    db.Model(&user).Association("Orders").Find(&orders)
    fmt.Println(orders)
}

0 Answers
Related