gorm没有将db值映射到实体

问题描述 投票:0回答:1

嗨,下面是我的postgresql表的Entity类和结构。gorm的find查询返回所需的行数,但该对象未使用值更新。

实体:

type Flow struct {
Id             int                    `gorm:"primary_key";"AUTO_INCREMENT"; "column:id"`
Name           string                 `gorm:"type:varchar(200)"; "column:name"`
Version        string                 `gorm:"column:version"`
Type           enum.FlowType          `gorm:"column:type"`
Status         flow_status.FlowStatus `gorm:"column:status"`
UniqueMmid     uuid.UUID              `gorm:"type:varchar(36)"; "column:uniquemmid"`
SomeXYVersions *[]uint8               `gorm:"column:somexyzversions"`
CreatedOn      time.Time              `gorm:"column:createdon"`
DeletedOn      time.Time              `gorm:"column:deletedon"`
}

表结构:

     Column     |            Type             | Collation | Nullable |              Default              
----------------+-----------------------------+-----------+----------+-----------------------------------
 id             | integer                     |           | not null | 
nextval('flows_id_seq'::regclass)
 name           | character varying           |           | not null | 
 version        | character varying           |           | not null | 
 type           | character varying           |           | not null | 
 status         | character varying           |           | not null | 
 uniquemmid     | uuid                        |           | not null | 
 somexyversions | json                        |           |          | 
 createdon      | timestamp without time zone |           | not null | 
 deletedon      | timestamp without time zone |           |          | 
 Indexes:
    "flows_pkey" PRIMARY KEY, btree (id)

我正在使用gorm ORM。下面的代码显示了我如何尝试获取数据库记录:

flow := &model.Flow{UniqueMmid: uuid.FromStringOrNil(xyzid)}
dbConnection.Debug().First(&flow)

当我检查流对象时,它不包含任何值。有人可以帮我找出问题的原因。

postgresql go gorm
1个回答
0
投票

您必须将变量的地址发送给First函数。

但是您正在发送指针的指针。正确的方法是;

dbConnection.Debug().First(flow)
© www.soinside.com 2019 - 2024. All rights reserved.