【问题标题】:Yesod Persistent: SQLite table with id row onlyYesod Persistent:只有 id 行的 SQLite 表
【发布时间】:2014-05-07 07:17:56
【问题描述】:

我的模型如下所示:

TestGroup
TestPerson
    firstName Text
    lastName Text
    testGroupId TestGroupId
TestObject
    objectName Text
    testGroupId TestGroupId

在这种情况下,TestGroup 表中唯一的内容是 testGroupId。多个 TestPerson 可以在一个组中(一对多),一个组可以有多个测试对象(也可以是一对多)。

以下代码编译并运行,但产生 SQLite 错误:

postAddTestPersonR :: Handler Value
postAddTestPersonR = do
    newTestPerson <- parseJsonBody :: Handler (Result TestPerson)
    case newTestPerson of
      Success s -> runDB $ do
        newTestGroup <- insert $ TestGroup
        _ <- insert $ TestPerson (firstName s) (lastName s) newTestGroup
        return $ object ["message" .= "it worked"]
      Error e -> return $ object ["message" .= e]

错误:

"INSERT INTO \\\"test_group\\\"() VALUES()\": near \")\": syntax error)"

如果我打开数据库并以这种方式手动添加它,我会得到一个新的 ID 号:

INSERT INTO test_group VALUES (null);

我应该尝试在原始 SQL 中执行此操作,还是有办法通过持久化来解决此问题。一个简单的解决方案是向 TestGroup 添加一个虚拟变量并执行 insert $ TestGroup Nothing 但这有点骇人听闻,我想知道是否有解决方法。

【问题讨论】:

标签: sqlite haskell yesod persistent


【解决方案1】:

这是 Yesod 的内部问题。已解决:https://github.com/yesodweb/persistent/issues/222

【讨论】:

    猜你喜欢
    • 2012-07-28
    • 2012-06-14
    • 1970-01-01
    • 2015-10-22
    • 1970-01-01
    • 1970-01-01
    • 2020-03-17
    • 2015-03-23
    • 1970-01-01
    相关资源
    最近更新 更多