New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass existing [EntityDef]
into mkPersist
#1241
Comments
I think we can!
Given [| entityDef (Proxy :: Proxy $(pure theType)) |] which produces an Now, we don't yet have those |
Oh, duh, same way we get around mkPersist sqlSettings $ mappend $(entityDefsInScope) [persistLowerCase|
Bar
foo FooId
name Text
|] It's still annoying to need to mappend them manually. It's also obnoxious to have to do |
Hmm, Eg:
When working with That'll end up doing a |
wait, maybe we could do the splicing in the quoter exp is basically quoteExp = \str -> do
es <- discoverEntities
new <- parseReferences ps str
pure (new <> es) but then we need some check or lookup in (really the quoter should not return data EntityQuoteResult = EntityQuoteResult
{ eqrDiscoveredEntities :: Map EntityNameHS EntityDef
, eqrParsedEntities :: Map EntityNameHS ParsedEntityDef
} then |
A problem with this is that the generated declarations don't know about any of the
EntityDef
s that are not provided as part of this invocation. So if you have two blocks, one of which definesUser
and another defining anOrganization
with auser UserId
field, the foreign key won't get properly invoked, since theliftAndFIxKeys
machinery won't find theUser
in the existing map of tables.This would fix #1073 as well. That issue has some good exploration on why this particular problem impacts foreign key generation.
persistent
figures that aBlahBlahId
type is a reference to aBlahBlah
model, and it tries to find theBlahBlah
model in aMap HaskellName EntityDef
that it constructs... from the[EntityDef]
that is passed in.A work-around is to... well, pass them in!
This requires that you do that
. mappend dependentDefs
for each one. But it should fix the issue.It's a bit annoying to tease these relationships together manually. And it's very easy to forget, especially since, well, everyone pretty much has. Can we do better?
The text was updated successfully, but these errors were encountered: