Skip to content

Commit

Permalink
Merge pull request #148 from stillalivx/master
Browse files Browse the repository at this point in the history
Allow allowNull property to primary key field
  • Loading branch information
eveningkid authored Nov 11, 2020
2 parents 3d302f0 + 98e9cd3 commit c1b2a93
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/helpers/fields.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type {
FieldOptions,
DataTypes,
FieldTypeString,
FieldType,
FieldOptions,
FieldProps,
FieldType,
FieldTypeString,
} from "../data-types.ts";

/** Add a model field to a table schema. */
Expand Down Expand Up @@ -31,8 +31,11 @@ export function addFieldToSchema(
.getComputedPrimaryType();

if (relationshipPKType === "integer") {
const foreignField = table[relationshipPKType](fieldOptions.name)
.notNullable();
const foreignField = table[relationshipPKType](fieldOptions.name);

if (!relationshipPKProps.allowNull) {
foreignField.notNullable();
}

if (relationshipPKProps.autoIncrement) {
foreignField.unsigned();
Expand Down

0 comments on commit c1b2a93

Please sign in to comment.