为了账号安全,请及时绑定邮箱和手机立即绑定

go-pg“属于”同一表的2个字段

go-pg“属于”同一表的2个字段

Go
GCT1015 2021-04-16 15:17:26
我正在使用https://github.com/go-pg/pg来处理这些问题,使基本的属于关系的问题很大。所以基本上我有一个表,该表的列receipient_id和sender_id都指向同一用户表。这是我的代码和结果:type Transaction struct {    Id              int    Receipient      *User  `json:"receipient_id" sql:"-" validate:"required"`    Sender          *User  `json:"sender_id" sql:"-" validate:"required"`    TransactionType int    `json:"transaction_type" validate:"required"`    Status          int    `json:"status" validate:"required"`    Ammount         int    `json:"ammount" validate:"required"`    CreatedAt       string `json:"created_at" validate:"required"`}err = database.DBCon.Model(&transactions).Select()if err != nil {    return transactions, err}16:51:15.754 V1TransactionListPOST ▶ ERRO 006 supppers [Transaction<id:1 receipient:<nil> sender:<nil> transaction_type:0 status:1 ammount:100 created_at:1533650239]2018/08/07 16:51:15 http: panic serving [::1]:50157: runtime error: invalid memory address or nil pointer dereferencegoroutine 5 [running]:net/http.(*conn).serve.func1(0xc42036fd60) ...这是实际的数据库:SELECT * FROM transactions;-[ RECORD 1 ]----+-----------id               | 1receipient_id    | 23sender_id        | 24transaction_type | 0status           | 1ammount          | 100created_at       | 1533650239SELECT * FROM users;-[ RECORD 1 ]---------+-------------------------------------------------------------id                    | 23email                 | testss@gmail.comusername              | damn herepassword              | $2a$10$ABBHfgwhnepqKitBoiQ2bOcPfGjUIjio33uL52R88Lk2XhcfGwn26user_type             | 2profile_id            | 1status                | 2confirm_token         |recover_token         |recover_token_expiry  |recover_secret_answer | $2a$10$xPwZk2LanxXf1lvCvp29IuyHav88m5dGXo8Ao0f5A1aV1zwh5t6le
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 226 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号