bee icon indicating copy to clipboard operation
bee copied to clipboard

How can a table associated with a foreign key be saved?

Open kanyways opened this issue 6 years ago • 0 comments

go struct

type User struct {
      Id int
      Name string
}

type Info struct {
      InfoId int
      Title string
      User *User `orm:"rel(one)"`
}

db tables

table user (
        id int pk,
        name varchar
)

table info (
        info_id int pk,
        title varchar,
        user_id int
)

Q

The following structure can be used for the following query.

.RelatedSel () can fill in the associated object, that is, the name in the user table can be queried. But now I can't use orm.NewOrm (.Insert) (info) to save it.

I would like to ask you, as shown in the above structure, how do I deal with saving and associative queries?

kanyways avatar May 04 '18 04:05 kanyways