如何在使用生成的类型时合格命名字段

huangapple go评论54阅读模式
英文:

How to qualify name of a field when using generated types

问题

怎样在这样的函数中给字段命名合格:

let sortedIssues :: [Issue] = sortOn updatedAt issues

我的 issues 表中有一个 updated_at 列。然而,我还有另一个表格,其中也有一个 updated_at 列,所以编译器不知道我在上面的函数中指的是哪一个。

尝试将上述内容标识为 Issue.updatedAt 不起作用,因为没有 Issue 模块。由于 IHP 生成的类型都在同一个模块中,导入 Generated.Types 也没有帮助。

英文:

How do you qualify the name of a field within a function like this:

let sortedIssues :: [Issue] = sortOn updatedAt issues

I have an issues table with an updated_at column. However, I also have another table with an updated_at column so the compiler does not know which one I am referring to in the above function.

Trying to qualify the above as Issue.updatedAt does not work since there is no Issue module. The IHP-generated types are all within just one module as well, so importing Generated.Types does not help.

答案1

得分: 2

最好在这里使用点表示法以避免此问题:

let sortedIssues :: [Issue] = sortOn (.updatedAt) issues

这种简写形式是以下代码的缩写:

let sortedIssues :: [Issue] = sortOn (\issue -> issue.updatedAt) issues
英文:

It's best to use dot notation here to avoid this problem:

let sortedIssues :: [Issue] = sortOn (.updatedAt) issues

This short form notation is a shorthand for this:

let sortedIssues :: [Issue] = sortOn (\issue -> issue.updatedAt) issues

huangapple
  • 本文由 发表于 2023年4月6日 20:51:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/75949744.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定