结构体构建

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. CF-1072-C. Cram Time(贪心,数学)

    CF-1072-C. Cram Time http://codeforces.com/contest/1072/problem/C 题意: 第一天有 a 小时,第二天有 b 小时.第 k 个任务需要 ...

  2. [POJ] 3362 Telephone Lines

    Telephone Lines Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7978 Accepted: 2885 Descr ...

  3. 蓝牙学习(2)USB Adapter

    主要分析一下蓝牙USB Adapter使用USB接口传输HCI包的实现及过程. 参照上面的Bluetooth core system architecture图, 蓝牙USB Adapter作为Blu ...

  4. Mac OS X下安装Vue脚手架(vue-cli)

    前言 Vue作为前端三大框架(Angular,React,Vue)之一,号称是最简单,最容易上手的框架,同时也是行内的大趋势,还可以用来开发最火的小程序.具有开发快,双向数据流等特点,有些人认为Vue ...

  5. Python-小游戏题目

    猜年龄游戏 n = 0 rayn_age = 19 a = {0:'666',1:'777',2:'888'} while n <3: age = input('请输入你的年龄:') age = ...

  6. cf 1016D

    D. Vasya And The Matrix time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  7. ajax动态刷新下拉框

    动态post,避免直接给页面传输大量数据 /** * ajax通过商品刷新供应商 * by_kangyx * @throws IOException */ @RequestMapping(params ...

  8. ci $this->load->database()

    http://pengbotao.cn/codeigniter-database.html

  9. c++ string char* 获取输入值的区别

    #include <iostream> #include <string> using namespace std; void reverseStr(string &s ...

  10. CentOS 下通过命令登录Mysql

    CentOS 下通过命令登录Mysql: mysql -uroot -p 按回车键后输入密码