我有一个像这样的持久模型:
Organization sql=organizations
Id UUID default=uuid_generate_v1mc
name Text
UniqueOrganizationName name
deriving Show Eq Typeable
我想在我的Yesod routes
文件中使用组织名称,如下所示:
/#OrganizationName/onboarding/business/about OnboardingBusinessAboutR POST
使用OrganizationName
或UniqueOrganizationName
会出现此错误:
/Users/maximiliantagher/Documents/Mercury/hs/mercury-web-backend/src/Foundation.hs:41:1: error:
• Data constructor ‘OrganizationName’ cannot be used here
(Perhaps you intended to use TypeInType)
• In the type ‘OrganizationName’
In the definition of data constructor ‘OnboardingBusinessAboutR’
In the data instance declaration for ‘Route’
我可以使用newtype作为解决方法,只是想知道是否有必要。
我认为缺少PathPiece
实例是一个问题,但如果只是那个,则错误将是No instance for (PathPiece ...)
。
使用OrganizationName
或UniqueOrganizationName
都可以。
答案 0 :(得分:2)
OrganizationName
类型是构造函数,因为这是在selectList
等持久性机制中使用的。实际上,name
是Organization
类型的Text
构造函数的参数,因此您只需在路线中使用#Text
。