英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论