Suppose I have these three structs:
type A struct {
Id int
Field string
Bs []B
}
type B struct {
Id int
Field string
Cs []C
}
type C struct {
Id int
Field string
}
And I have these three tables in the test database:
create table a (
Id int not null auto_increment,
Field varchar(40) not null,
primary key (Id)
);
create table b (
Id int not null auto_increment,
Field varchar(40) not null,
Fk int not null,
foreign key (FK) references a (Id),
primary key (Id)
);
create table c (
Id int not null auto_increment,
Field varchar(40) not null,
Fk int not null,
foreign key (FK) references b (Id),
primary key (Id)
);
How can I save & get a collection/slice of A
in my test database using gorm library?