Skip to content

Commit

Permalink
fix(entity-generator): try to resolve errors for foreign keys without…
Browse files Browse the repository at this point in the history
… indexes

Related #5364
  • Loading branch information
B4nan committed Mar 24, 2024
1 parent 184cdd4 commit f2094ab
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/knex/src/schema/DatabaseTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,12 +585,12 @@ export class DatabaseTable {
fk: ForeignKey,
namingStrategy: NamingStrategy,
schemaHelper: SchemaHelper,
fkIndex: IndexDef,
fkIndex: IndexDef | undefined,
nullable: boolean,
propNameBase: string,
) {
const prop = this.getPropertyName(namingStrategy, propNameBase, fk);
const kind = (fkIndex.unique && !fkIndex.primary) ? this.getReferenceKind(fk, fkIndex) : this.getReferenceKind(fk);
const kind = (fkIndex?.unique && !fkIndex.primary) ? this.getReferenceKind(fk, fkIndex) : this.getReferenceKind(fk);
const type = this.getPropertyTypeForForeignKey(namingStrategy, fk);

const fkOptions: Partial<EntityProperty> = {};
Expand Down Expand Up @@ -627,9 +627,9 @@ export class DatabaseTable {
kind,
...columnOptions,
nullable,
primary: fkIndex.primary || !fk.columnNames.some(columnName => !this.getPrimaryKey()?.columnNames.includes(columnName)),
index: !fkIndex.unique ? fkIndex.keyName : undefined,
unique: (fkIndex.unique && !fkIndex.primary) ? fkIndex.keyName : undefined,
primary: fkIndex?.primary || !fk.columnNames.some(columnName => !this.getPrimaryKey()?.columnNames.includes(columnName)),
index: !fkIndex?.unique ? fkIndex?.keyName : undefined,
unique: (fkIndex?.unique && !fkIndex.primary) ? fkIndex.keyName : undefined,
...fkOptions,
};
}
Expand Down

0 comments on commit f2094ab

Please sign in to comment.