Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 3120 #7277

Merged
merged 8 commits into from
Feb 8, 2021
Merged

Fix 3120 #7277

merged 8 commits into from
Feb 8, 2021

Conversation

Saniol
Copy link
Contributor

@Saniol Saniol commented Jan 14, 2021

Description of change

Fixes #3120 by adding a new relation option "createForeignKeyConstraints". That's updated version of #7112 PR by @alpharder, with fixes suggested by @nebkat and updated tests & docs.

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run lint passes with this change
  • npm run test passes with this change (there are some linter errors not related to those changes - mainly in exxisting test cases)
  • This pull request links relevant issues as Fixes #0000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change
  • The new commits follow conventions explained in CONTRIBUTING.md

Copy link
Contributor

@nebkat nebkat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't joinColumns and inverseJoinColumns still be set here, even if there are no foreign keys?

registerForeignKeys(...foreignKeys: ForeignKeyMetadata[]) {
this.foreignKeys.push(...foreignKeys);
this.joinColumns = this.foreignKeys[0] ? this.foreignKeys[0].columns : [];
this.inverseJoinColumns = this.foreignKeys[1] ? this.foreignKeys[1].columns : [];
this.isOwning = this.isManyToOne || ((this.isManyToMany || this.isOneToOne) && this.joinColumns.length > 0);
this.isOneToOneOwner = this.isOneToOne && this.isOwning;
this.isOneToOneNotOwner = this.isOneToOne && !this.isOwning;
this.isManyToManyOwner = this.isManyToMany && this.isOwning;
this.isManyToManyNotOwner = this.isManyToMany && !this.isOwning;
this.isWithJoinColumn = this.isManyToOne || this.isOneToOneOwner;
}

If so, last paragraph of my comment describes the necessary changes.

@Saniol
Copy link
Contributor Author

Saniol commented Jan 18, 2021

@nebkat you're right, I missed that... PR updated

Copy link
Contributor

@nebkat nebkat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now!

@@ -56,13 +56,14 @@ export class RelationJoinColumnBuilder {
*/
build(joinColumns: JoinColumnMetadataArgs[], relation: RelationMetadata): {
foreignKey: ForeignKeyMetadata|undefined,
columns: ColumnMetadata[],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just rename this field to joinColumns?

Copy link
Contributor Author

@Saniol Saniol Jan 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it - and I'm worried that it might be confusing, as this function already takes joinColumns (JoinColumnMetadataArgs type) as argument, but in the result columns type is ColumnMetadata[] - so I've decided to follow same naming as for types. Please let me know, if you have another idea how to resolve that naming conflict

action: string;

@ManyToOne(type => Person, {
createForeignKeyConstraints: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think if we just call it constraint: false ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could there be confusion with unique constraints? I think there is some driver that requires a unique on foreign keys.

@pleerock pleerock merged commit cb17b95 into typeorm:master Feb 8, 2021
@pleerock
Copy link
Member

pleerock commented Feb 8, 2021

Thank you for contribution! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to disable foreign keys creation
4 participants