Skip to content

Commit

Permalink
Adapt compileBuild
Browse files Browse the repository at this point in the history
  • Loading branch information
amitaibu committed Aug 26, 2024
1 parent 97ede64 commit 351f5b2
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions ihp-ide/IHP/SchemaCompiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -779,10 +779,28 @@ instance FromRow #{modelName} where


compileBuild :: (?schema :: Schema) => CreateTable -> Text
compileBuild table@(CreateTable { name, columns }) =
compileBuild table@(CreateTable { name, columns, inherits }) =
"instance Record " <> tableNameToModelName name <> " where\n"
<> " {-# INLINE newRecord #-}\n"
<> " newRecord = " <> tableNameToModelName name <> " " <> unwords (map toDefaultValueExpr columns) <> " " <> (columnsReferencingTable name |> map (const "def") |> unwords) <> " def\n"
<> " newRecord = " <> tableNameToModelName name <> " " <> unwords (map toDefaultValueExpr allColumns) <> " " <> (allColumnsReferencingTable |> map (const "def") |> unwords) <> " def\n"
where
(parentColumns, parentColumnsReferencingTable) = case inherits of
Nothing -> ([], [])
Just parentTableName ->
let parentTableDef = findTableByName parentTableName
in case parentTableDef of
Just parentTable ->
(parentTable.unsafeGetCreateTable.columns, columnsReferencingTable parentTableName)

Nothing -> error $ "Parent table " <> cs parentTableName <> " not found for table " <> cs name <> "."

allColumns = columns <> parentColumns

allColumnsReferencingTable = columnsReferencingTable name <> parentColumnsReferencingTable






compileDefaultIdInstance :: CreateTable -> Text
Expand Down

0 comments on commit 351f5b2

Please sign in to comment.