【发布时间】:2021-07-10 10:30:24
【问题描述】:
我有两张桌子,
SET search_path = public;
CREATE TABLE IF NOT EXISTS changelog
(
id BIGINT NOT NULL PRIMARY KEY,
object_type TEXT,
object_id BIGINT,
parent_type TEXT,
parent_id BIGINT,
action TEXT,
field TEXT,
old_value TEXT,
new_value TEXT,
comment_id INTEGER,
created_on TIMESTAMP WITHOUT TIME ZONE,
created_by BIGINT
);
CREATE TABLE IF NOT EXISTS changelog_comments
(
id INTEGER NOT NULL PRIMARY KEY,
comment TEXT,
created_on TIMESTAMP WITHOUT TIME ZONE,
created_by BIGINT
);
SET search_path = DEFAULT;
我想为返回字段的更改日志实现搜索方法
"objectType"
"objectId"
"parentType"
"parentId"
"action"
"field"
"oldValue"
"newValue"
"comment"
"createdBy"
"createdOn"
如您所见,结果来自两个表的连接。
我找到了https://gorm.io/docs/preload.html,但老实说,我不明白如何才能实现我的需要。
我认为以下内容可能会有所帮助
type ChangelogResponseItem struct {
ObjectType string `json:"objectType"`
ObjectID uuid.UUID `json:"objectId"`
ParentType string `json:"parentType"`
ParentID uuid.UUID `json:"parentId"`
Action string `json:"action"`
Field *string `json:"field"`
OldValue *string `json:"oldValue"`
NewValue *string `json:"newValue"`
Comment *string `json:"comment"`
CreatedBy *uint64 `json:"createdBy"`
CreatedOn *time.Time `json:"createdOn"`
}
问题是如何从 GORM 中提到的表格中得到我提到的内容?
【问题讨论】: