Skip to content

Commit

Permalink
code-gen: fix field types of update partial for optional fields (#647)
Browse files Browse the repository at this point in the history
Closes #643
  • Loading branch information
dirkdev98 authored Feb 2, 2021
1 parent 824da04 commit bde2631
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/code-gen/src/generator/sql/partial-type.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isNil } from "@compas/stdlib";
import { ObjectType } from "../../builders/ObjectType.js";
import { upperCaseFirst } from "../../utils.js";
import { js } from "../tag/index.js";
Expand Down Expand Up @@ -73,6 +74,15 @@ export function createPartialTypes(context) {
...fieldType,
isOptional: true,
};

// Create correct types by setting allowNull, since the value will be used in the update statement
if (fieldType.isOptional && isNil(fieldType.defaultValue)) {
updatePartial.keys[key].validator = Object.assign(
{},
updatePartial.keys[key].validator,
{ allowNull: true },
);
}
}

type.partial = {
Expand Down
4 changes: 2 additions & 2 deletions packages/store/src/generated/types.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bde2631

Please sign in to comment.