想象一下,您有两个模型(Foo和Bar)并且它们都相互引用(Foo具有barRef类型为BarId,Bar具有fooRef类型为FooId)。一切顺利:
#!/usr/bin/env stack
{- stack script --resolver=lts-9.21 --package=persistent-template -}
{-# LANGUAGE GADTs, GeneralizedNewtypeDeriving, QuasiQuotes, TemplateHaskell #-}
{-# LANGUAGE TypeFamilies, MultiParamTypeClasses #-}
import Database.Persist.TH
mkPersist sqlSettings [persistLowerCase|
Foo
barModel BarId
fooField Int
Bar
fooModel FooId
barField Int
|]
main = pure ()
但是如果我将引用类型包装为Maybe(只是一个例子,它可以是Vector或其他任何东西):
#!/usr/bin/env stack
{- stack script --resolver=lts-9.21 --package=persistent-template -}
{-# LANGUAGE GADTs, GeneralizedNewtypeDeriving, QuasiQuotes, TemplateHaskell #-}
{-# LANGUAGE TypeFamilies, MultiParamTypeClasses #-}
import Database.Persist.TH
mkPersist sqlSettings [persistLowerCase|
Foo
barModel (Maybe BarId)
fooField Int
Bar
fooModel FooId
barField Int
|]
main = pure ()
它失败并出现此错误:
Not in scope: type constructor or class ‘BarId’
我应该如何解决这个问题?