2014-03-28 7 views
1

내 모델은 다음과 같습니다Yesod 영구 : ID 행과 SQLite는 테이블은

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

을 TestGroup 테이블의 유일한 testGroupId이 경우에. 여러 명의 TestPerson은 하나의 그룹 (일대 다)에 속할 수 있으며 한 그룹에는 여러 개의 테스트 개체 (일대 다)가있을 수 있습니다.

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] 

오류 : I 데이터베이스를 열고 수동으로 작동이 방법을 추가 한 경우

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

내가 얻을

다음 코드는 SQLite는 오류를 컴파일하고 실행하지만 생산 새 ID 번호 :

INSERT INTO test_group VALUES (null); 

원시 SQL에서이 작업을 수행해야합니까, 아니면 방법이 있습니까? 이 주변에 지속됩니다. 간단한 해결책은 TestGroup에 더미 변수를 추가하고 insert $ TestGroup Nothing을 수행하는 것입니다.하지만 그것은 약간 hackish하고 주위에 방법이 있는지 알고 싶습니다.

+0

더미 변수를 사용하는 것 이외의 다른 해결책이 있는지 모르겠습니다. 누군가 내가 https://github.com/yesodweb/persistent/issues/222 문제를 만들 것을 제안했습니다. – MCH

답변