2014-03-28 26 views
1

我的模型如下所示:耶索德持久性:與ID行SQLite表只有

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

在這種情況下,在TestGroup表中的唯一的事情就是testGroupId。多個TestPersons可以在一個組中(一對多),並且一個組可以有多個測試對象(也是一對多)。

下面的代碼編譯和運行,但產生的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)" 

如果我打開數據庫和手動添加這樣它的作品,我也得到一個新的身份證號碼:

INSERT INTO test_group VALUES (null); 

我應該只是嘗試在原始SQL中執行此操作還是有辦法堅持下去。一個簡單的解決方案就是給TestGroup添加一個虛擬的可能變量,然後做insert $ TestGroup Nothing,但這有點駭人聽聞,我想知道是否有解決方法。

+0

我不知道現在是否有解決方案,而不是使用虛擬變量。有人建議我創建一個問題https://github.com/yesodweb/persistent/issues/222 – MCH

回答