结构体构建

type PlansApproval struct {

    ID          uint
    Plans_Id    int    //plans编号
    UpdateUser  int    //更新者
    Approval    string //批示内容
    Record_date time.Time
    CreateUser  int
    ProfileID   int
    Profile     Profile `gorm:"ForeignKey:ProfileID;AssociationForeignKey:ID;"`

    PlansApprovalsReply []PlansApprovalsReply `gorm:"ForeignKey:ID;AssociationForeignKey:ID;"`
}
type PlansApprovalsReply struct {
    ID                            int
    Plans_id                      int
    Plans_approvals_reply_content string
    Plans_approvals_reply_date    time.Time
    Plans_approvals_reply_user    int
    User                          User `gorm:"ForeignKey:Plans_approvals_reply_user;AssociationForeignKey:ID"`
}
type PlansComment struct {
    ID                 uint
    Plans_Id           int //plans编号
    CreateUser         int
    UpdateUser         int //更新者
    Record_date        time.Time
    Comment            string //评论内容
    ProfileID          int
    Profile            Profile              `gorm:"ForeignKey:ProfileID;AssociationForeignKey:ID"`
    User               User                 `gorm:"ForeignKey:ProfileID;AssociationForeignKey:ID"`
    PlansCommentsReply []PlansCommentsReply `gorm:"ForeignKey:ID;AssociationForeignKey:ID;"`
}
type PlansCommentsReply struct {
    ID                          int
    Plans_id                    uint
    Plans_comment_reply_content string
    Plans_comment_reply_date    time.Time
    Plans_comment_reply_user    int
    User                        User `gorm:"ForeignKey:Plans_comment_reply_user;AssociationForeignKey:ID"`
}
type User struct {
    gorm.Model
    Username   string
    Avatar     string `gorm:"default:'/img/user.jpg'"`
    Profile_id int
}

type Profile struct {
    gorm.Model
    Realname    string    `form:"Realname" json:"Realname"`
    Sex         int       `form:"Sex" json:"Sex,string"`
    Birth       time.Time `form:"Birth" json:"Birth" time_format:"2006-01-02"`
    Email       string    `form:"Email" json:"Email"`
    Webchat     string    `form:"Webchat" json:"Webchat"`
    Qq          string    `form:"Qq" json:"Qq"`
    Phone       string    `form:"Phone" json:"Phone"`
    Tel         string    `form:"Tel" json:"Tel"`
    Address     string    `form:"Address" json:"Address"`
    Emercontact string    `form:"Emercontact" json:"Emercontact"`
    Emerphone   string    `form:"Emerphone" json:"Emerphone"`
    Departid    int64
    Positionid  int64
    Lognum      int
    Ip          string
    Lasted      int64
    Depart      Depart `gorm:"ForeignKey:Departid;AssociationForeignKey:ID"`
    User        User   `gorm:"ForeignKey:ID;AssociationForeignKey:ID;"`
}

type Depart struct {
    ID   int
    Name string
    Desc string
}

预加载
func GetPlansCommentByPlansidList(p PlansComment, q util.Query) (results map[string]interface{}, err error) {
    results = make(map[string]interface{})

    var pc []PlansComment

    pc = make([]PlansComment, 0)

    var total int

    err = db.Orm.Debug().Preload("Profile.Depart").Preload("PlansCommentsReply.User").Preload("Profile.User").First(&pc, p.CreateUser).Where("plans_id = ?", p.Plans_Id).Find(&pc).Error

    db.Orm.Table("plans_comments").Where("plans_id = ?", p.Plans_Id).Where("deleted_at IS NULL").Count(&total)



    results["items"] = pc

    results["total"] = total



    return results, err



}

gorm 结构体 预加载的更多相关文章

  1. Gorm 预加载及输出处理(二)- 查询输出处理

    上一篇<Gorm 预加载及输出处理(一)- 预加载应用>中留下的三个问题: 如何自定义输出结构,只输出指定字段? 如何自定义字段名,并去掉空值字段? 如何自定义时间格式? 这一篇先解决前两 ...

  2. Gorm 预加载及输出处理(一)- 预加载应用

    单条关联查询 先创建两个关联模型: // 用户模型 type User struct { gorm.Model Username string `gorm:"type:varchar(20) ...

  3. Gorm 预加载及输出处理(三)- 自定义时间格式

    前言 Gorm 中 time.Time 类型的字段在 JSON 序列化后呈现的格式为 "2020-03-11T18:26:13+08:00",在 Go 标准库文档 - time 的 ...

  4. javascript设计模式实践之代理模式--图片预加载

    图片的预加载就是在加载大图片前,先显示一个loading.gif,就算在网络比较慢的时候也能让人知道正在加载,总比啥反应都没有强. 下面这段代码就是预加载的一个简单的实现,假设先不处理加载图片时的on ...

  5. ViewPager的刷新、限制预加载、缓存所有

    [框架]: 公共部分:左侧菜单.TitleBar.RadioGroup(3个RadioButton:X.Y.Z) 选择X页面:指示器+ViewPager [要达成的效果]: (1)左侧选择A,进入X页 ...

  6. jquery实现图片预加载

    使用jquery实现图片预加载提高页面加载速度和用户体,本就为大家详细分析jquery图片预加载的实现原理. 什么时候使用图片预加载? 如果页面使用了很多不是最初加载便可见的图片,有必要进行预加载: ...

  7. 资源预加载preload和资源预读取prefetch简明学习

    前面的话 基于VUE的前端小站改造成SSR服务器端渲染后,HTML文档会自动使用preload和prefetch来预加载所需资源,本文将详细介绍preload和prefetch的使用 资源优先级 在介 ...

  8. 基于spring的web项目启动时预加载数据到ServletContext

    1.要在web启动时预加载数据到ServletContext,实现方法有很多,一种比较简单的方案就是: 1)新建一个bean,定义其初始化方法: <bean id="beanId&qu ...

  9. pre-network android 网络优化预加载框架

    网络优化是所有app开发中非常重要的一部分,如果将网络请求前置就是在点击跳转activity之前开始网络加载那么速度将会有质的提升.也就是网络预先加载框框架. 网络预加载框架,监听式网络前置加载框架- ...

随机推荐

  1. java在线聊天项目 swt可视化窗口Design 重新设计聊天窗口

    设计的聊天窗口如下: 制作过程: 首先,在默认的BorderLayout视图下, 上边也就是North处添加一个JPanel,将Layout调整为BorderLayout,West放一个JLabel用 ...

  2. iOS 优秀博客

    中文 iOS/Mac 开发博客列表 GitHub 上排名前 100 的 Objective-C 项目简介 GitHub 上都有哪些值得关注学习的 iOS 开源项目? iOS开发系列文章(持续更新……) ...

  3. Git学习——创建与合并分支

    分支概念 当前我们所在的分支是master(主分支),可以通过创建分支: git branch <branch_name> 创建完成后,可以查看当前的分支状态: git branch 当前 ...

  4. Java实现——字符串分割以及复制目录下的所有文件

    0.  前言 今天有个需求,把Android中data/data目录下指定(通过读预置的XML文件)的多个应用下的多个目录全部内容通过OTG模式复制到U盘中. 首先读取XML文件内的某个节点的属性值, ...

  5. python基础学习笔记——深浅拷贝

    2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 lst1 = ["⾦⽑狮王", "紫衫⻰王&qu ...

  6. Yii2.0 添加分类category model类

    <?php namespace app\models; use yii\db\ActiveRecord; use Yii; use yii\helpers\ArrayHelper; class ...

  7. Leetcode 400.第n个数

    第n个数 在无限的整数序列 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...中找到第 n 个数字. 为整形范围内 ( n < 231). 示例 1: 输入: 3 输出 ...

  8. Linux下dpkg的用法

    转自:http://blog.csdn.net/fireblue1990/article/details/52627952 dpkg是一个Debian的一个命令行工具,它可以用来安装.删除.构建和管理 ...

  9. Brownie Slicing(二分枚举答案)

    描述 Bessie has baked a rectangular brownie that can be thought of as an RxC grid (1 <= R <= 500 ...

  10. SPOJ - ADALIST,双端队列入门模板!

    ADALIST - Ada and List 这道题时限6.5s,激动人心啊,好多人STL一顿乱写AC,哈哈,如果熟悉双端队列的话这道题其实是很水的. 题意:n个数的数列,然后接下来Q次操作,每次可以 ...