Golang gorm has many self refrence not working for me

Why gorm has many self refrence not working for me

type Comment struct {
    gorm.Model
   Text    string     `sql:"type:text;"`
   Comments    []Comment    `gorm:"foreignkey:ID;associatdion_foreignkey:ParentID"`
   ParentID    uint
   PostID    uint
   UserID    uint
}

this is the error:

invalid association []

this is my code to give result

var comments Comment
var child []Comment
db.First(&comments, 3)
db.Model(&comments).Related(&child)
fmt.Println("comments: ", child)

There are two camps advocating ORM or not. To add another layer upon plain SQL is (IMHO) limiting, slowing down and add extra learning time.

But on the other side there are many developers that claims the opposite.

FWIW…

You miswrote association_foreignkey.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.