user User
user order Order
want to implement< hr >
A user can have N orders, and each order can only have one user
Model
type User struct {
Id int64
Name string
Order []*Order `orm:"reverse(many)"`
}
type Order struct {
Id int64
User *User `orm:"rel(fk)"`
CreatedAt time.Time
}
data Table:
user
order
< table > < thead > < tr > < th > id < / th > < th > user_id (foreign key) < / th > < th > created_at < / th > < / tr > < / thead > < tbody > < tr > < td > 1 < / td > < td > 1 < / td > < td > 2018-12-20 10:36:47 < / td > < / tr > < tr > < td > 2 < / td > < td > 1 < / td > < td > 2018-12-20 10:38:09 < / td > < / tr > < tr > < td > 3 < / td > < td > 1 < / td > < td > 2018-12-20 10:40:12 < / td > < / tr > < tr > < td > 4 < / td > < td > 2 < / td > < td > 2018-12-20 10:47:52 < / td > < / tr > < / tbody > < / table > get order data as set above
:
{
"Id":1,
"CreatedAt":"2018-12-20T10:36:47+08:00",
"User":{
"Id":1,
"Name":"test",
"Order":null
}
}
gets user data, however, the value that gets Order
is null
. If you want to get all the orders obtained by a user, do you want to process them through business logic?
{
"Id":1,
"Name":"test",
"Order":null
}
the initial contact with beego, documents made me look confused! Ask for advice!