【发布时间】:2018-07-09 11:17:08
【问题描述】:
我是 GOlang 和 GORM 的新手,我对如何使用 GORM 进行多表连接有些困惑。
例子:
表格:
Department - Fields (gorm.Modal, dep_name)
Employee - Fields (gorm.Modal, emp_id, emp_name, department_id) //employee is department table child
EmployeeContact - Fields (gorm.Modal, employee_id, emp_contact_no)//Employee contact table is employee table child
查询
SELECT * FROM department d, employee e, employeeContact ec WHERE d.id = e.department_id and e.id = ec.employee_id
如何使用 GORM 进行上述查询?
【问题讨论】:
-
db.Joins() 可用于在 gorm 中执行连接。检查它是否能解决您的问题。
-
是的,我试过了,但是我怎样才能使用多个表呢? @AnkitDeshpande