Your Question

I have two tables

type PayLog struct {
    ID            int        `json:"id" gorm:"column:id"`
    Description   string     `json:"description" gorm:"column:description"`
    OutTradeNo    string     `json:"out_trade_no" gorm:"column:out_trade_no"`
    TimeExpire    *time.Time `json:"time_expire" gorm:"column:time_expire"`
    Attach        string     `json:"attach" gorm:"column:attach"`
    Total         int        `json:"total" gorm:"column:total"`
    GoodsDetail   string     `json:"goods_detail" gorm:"column:goods_detail"`
    SubMerchantId int        `json:"sub_merchant_id" gorm:"column:sub_merchant_id"`
    CodeUrl       string     `json:"code_url" gorm:"column:code_url"`
    Created       string     `json:"created" gorm:"column:created"`
}
type SubMerchant struct {
    ID            *int    `json:"id"`
    SpAppid       *string `json:"sp_appid"`
    SpWechatid    *string `json:"sp_wechatid"`
    PayerClientIp *string `json:"payer_client_ip"`
    DeviceId      *string `json:"device_id"`
    StoreId       *string `json:"store_id"`
    Name          *string `json:"name"`
    AreaCode      *string `json:"area_code"`
    Address       *string `json:"address"`
    MerchantId    *int    `json:"merchant_id"`
}

When I query a single piece of data

var paylog PayLog
global.Orm.Table("PayLogTable").First(&paylog)

The results obtained without any query conditions are normal

When I add any query condition, id or other

var paylog payment.WechatPayLog
// global.Orm.Table("PayLogTable").Where("id = ?", 9).First(&paylog)
global.Orm.Table("PayLogTable").Where("out_trade_no = ?", "xxxxxxxxxxxxxxx").First(&paylog)

The results obtained

Id -> PayLog.Id Description -> PayLog.Id OutTradeNo -> PayLog.OutTradeNo TimeExpire -> ? Attach -> SubMerchant.PayerClientIp Total -> ? GoodsDetail -> ? SubMerchantId -> ? CodeUrl -> SubMerchant.Name Created -> SubMerchant.AreaCode

The document you expected this should be explained

Expected answer

normal corresponding data

Comment From: github-actions[bot]

This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days

Comment From: saeidee

This should have the same behavior with/without condition, however, based on your example I am guessing you are using payment.WechatPayLog not PayLog struct. If not please try to reproduce it in a playground PR.