feat (division): add fk and preloads for parent and childrens
This commit is contained in:
@@ -11,6 +11,12 @@ type CreateDto struct {
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
FilterDto
|
||||
Includes string `json:"includes"`
|
||||
Preloads []string `json:"-"`
|
||||
}
|
||||
|
||||
type FilterDto struct {
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Parent_Id *uint16 `json:"parent_id"`
|
||||
|
||||
@@ -87,6 +87,9 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(input.Includes) > 0 {
|
||||
input.Preloads = pu.GetPreloads(input.Includes)
|
||||
}
|
||||
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -47,9 +47,15 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Di
|
||||
tx = dg.I
|
||||
}
|
||||
|
||||
if len(input.Preloads) > 0 {
|
||||
for _, preload := range input.Preloads {
|
||||
tx = tx.Preload(preload)
|
||||
}
|
||||
}
|
||||
|
||||
tx = tx.
|
||||
Model(&e.Division{}).
|
||||
Scopes(gh.Filter(input)).
|
||||
Scopes(gh.Filter(input.FilterDto)).
|
||||
Count(&count).
|
||||
Scopes(gh.Paginate(input, &pagination)).
|
||||
Order("\"CreatedAt\" DESC")
|
||||
|
||||
Reference in New Issue
Block a user