- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在使用 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 dereference
goroutine 5 [running]:
net/http.(*conn).serve.func1(0xc42036fd60)
...
这是实际的数据库:
SELECT * FROM transactions;
-[ RECORD 1 ]----+-----------
id | 1
receipient_id | 23
sender_id | 24
transaction_type | 0
status | 1
ammount | 100
created_at | 1533650239
SELECT * FROM users;
-[ RECORD 1 ]---------+-------------------------------------------------------------
id | 23
email | testss@gmail.com
username | damn here
password | $2a$10$ABBHfgwhnepqKitBoiQ2bOcPfGjUIjio33uL52R88Lk2XhcfGwn26
user_type | 2
profile_id | 1
status | 2
confirm_token |
recover_token |
recover_token_expiry |
recover_secret_answer | $2a$10$xPwZk2LanxXf1lvCvp29IuyHav88m5dGXo8Ao0f5A1aV1zwh5t6le
-[ RECORD 2 ]---------+-------------------------------------------------------------
id | 24
email | anotehrtsts@gmail.com
username | removeusername
password | $2a$10$1tmCvZy5xo5zGz9C3g6YeeV8Wb149VwSTFhT1pcjb0zVasT.fbTKy
user_type | 2
profile_id | 1
status | 2
confirm_token |
recover_token |
recover_token_expiry |
recover_secret_answer | $2a$10$CeS5qgITVGBgWX7cumhbdOoAPOhg/Lc2NXDu.nY5RzK3PGCW26Ik2
最佳答案
我忘了添加 Id 列,这是一个工作示例:
type Transaction struct {
Id int
RecipientId int `json:"recipient_id"`
Recipient *User `pg:"fk:recipient_id"`
SenderId int `json:"sender_id"`
Sender *User `pg:"fk:sender_id"`
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"`
}
关于go-pg "belongs to"2个字段到同一个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51741669/
有一个网站曾经销售实体产品......现在他们想要销售一些完全不同的服务之王......比如信用套餐来向用户帐户收费(购买产品)或购买短信..诸如此类 所以数据库以前是这样的 order : user
所以,我一直在尝试用 SQL 编写查询,但遇到了问题。我正在尝试写一个“属于”的条件。我想要做的是,如果要获取的值属于另一个表中的列,则填充一件事,否则填充 null。 例如。 NAME table
如何为属于模型 B 或模型 C 但不属于两者的模型 A 编写关联? 假设我有一个员工模型、承包商模型和一个事件模型。关联如下: 员工有很多事件。 承包商有许多事件。 事件属于承包商或员工。 我是否创建
我想创建一个字符串,其中包含当前用户预期能够在键盘上输入的所有字符。对于英语文化中的用户,这将是 26 个大写字母和 26 个小写字母、10 个十进制数字和 30 多个符号。来自其他国家的用户会有一些
我不知道为什么我要为此苦苦挣扎,这似乎是一个非常简单的概念。所以我的挣扎让我觉得也许我的数据建模需要另一个组件...... 我正在使用 Laravel 5 并尝试定义一些模型关系。 BelongsTo
假设我有一个从给定软件工具调用的函数 foo(在 C/C++ 中)。 函数 foo 只允许写入由 foo 分配的内存或由 foo 调用的函数之一,但不允许写入写入由调用 foo 之前执行的函数分配的内
大家好,我目前在 FCC 上遇到这个算法挑战。这就是挑战的全部内容: 返回排序后应将值(第二个参数)插入数组(第一个参数)的最低索引。返回值应该是一个数字。 例如,getIndexToIns([1,2
edit - 根据下面的回复,我将重新审视我的设计。我认为我可以通过更加巧妙地设置我的业务目标和规则来避免这种困惑。感谢大家的帮助! -- 我有以下模型: S属于T T有很多S A,B,C,D,E (
我正在使用 https://github.com/go-pg/pg处理这些东西,在建立一个基本的属于关系方面有很大的问题。 所以基本上我有一个包含列 receipient_id 和 sender_id
我想定义non-line-termination-character = 在 lexer.mll .我试过let non_line_termination_character = [^('\x0D'
几周以来,我开始开发 CakePHP 项目。从一开始我就在为 Controller 内部的代码量而苦苦挣扎。在大多数情况下, Controller 的代码行数比模型多。通过了解“瘦 Controlle
因此,在我没有真正关注新发展的一段时间后,我再次研究了 MVVM,我注意到教程/指南等的数量已经大大增加。然而,MVVM 的大多数示例/示例实现都缺乏解释一些我不太清楚的东西。所有这些示例都非常简单,
Groovy版本2.4.8 Grails 2.5.1版 我试图使用like子句从Advisor表中提取行,并且如果该方法中传递了Firm名称,那么我只想从该Firm中提取Advisor。 我构造了两个
我是 DDD 概念的新手,我正在尝试设计一个严格遵循 DDD 和 Prism (WPF) 的解决方案结构。我正在堆放创建 DTO 项目(数据传输对象)的位置。据我所知,DDD 将有 4 个通用层: 演
假设我找到了一个元素: Element link = div.select("a:not([class])").first(); 我现在想知道这个特定 元素是否包含在 中-- 不一定是直系后代。 有
我正在创建一个非常简单的 Java Card Applet(版本 2.2.2),但我是 Java 卡的新手,我不知道如何将 .class 文件转换为 .cap 文件。我正在使用 converter.b
我正在寻求澄清是将代码放入 Controller 、实体还是提供服务。 我有“cardset”和“card”对象(其中许多后者嵌入前者 MongoDB 中),由普通的 PHP 类/对象表示。这些包含属
我是 ORM(和 GORM)的新手,如果这是一个明显的问题,我深表歉意,但它似乎没有被文档涵盖。 我将使用 examples from the documentation作为我的问题的基础 问题1:属
我想更好地理解类文件和内部/嵌套类,我想知道以下几点: 是InnerClasses属性用于引用“包含”类中的内部/嵌套类,还是在内部/嵌套类中用于引用“容器”类? 是InnerClasses类文件中的
我正在尝试使用 ibexpert gui 在 firebird 2.5 上创建我的第一个程序。 该过程将返回属于特定“PROCESS_ID”的“PROCESS_DATE”。我准备了以下代码: begi
我是一名优秀的程序员,十分优秀!