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

onUpdate option in association not working #16963

Open
3 of 6 tasks
mitkonikolov opened this issue Jan 15, 2024 · 0 comments
Open
3 of 6 tasks

onUpdate option in association not working #16963

mitkonikolov opened this issue Jan 15, 2024 · 0 comments
Labels
pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug v6

Comments

@mitkonikolov
Copy link

Issue Creation Checklist

  • I understand that my issue will be automatically closed if I don't fill in the requested information
  • I have read the contribution guidelines

Bug Description

I have a relatively simple SQL DB schema with just 4 entity types. I am able to build my code and update properties of the schema of my DB entities like field type/length etc. I have defined some simple associations. However, after reading documentation, source code, issues and examples, I am unable to set the onUpdate or onDelete properties of my foreign key association.

Reproducible Example

The code below creates a relationship between Users and Suppliers, but a foreignKey relationship gets created, the onUpdate field is not being set instead its value is 'No Action' when checked via Azure Data Studio. Trying to set onDelete does not work either.

User.belongsTo(Supplier, { foreignKey: 'supplierId', targetKey: 'id', onUpdate: 'CASCADE' });

After reading source code, I also tried setting the constraints and foreignKeyConstraint options to true, but this didn't make a difference.

User.belongsTo(Supplier, { foreignKey: 'supplierId', targetKey: 'id', constraints:true, foreignKeyConstraint: true, onUpdate: 'CASCADE' });

What do you expect to happen?

When the foreign key is created it should have an On update action set to 'Cascade'

What is actually happening?

The onUpdate is not being set. The logs of the DB updates (while the package builds) show that my onUpdate option is not being taken into account at all.

Executing (default): IF OBJECT_ID('[Users]', 'U') IS NOT NULL DROP TABLE [Users];
Executing (default): IF OBJECT_ID('[Users]', 'U') IS NULL CREATE TABLE [Users] ([email] NVARCHAR(255) , [active] BIT NULL, [createdAt] DATETIMEOFFSET DEFAULT getdate(), [externalId] NVARCHAR(50) NULL, [firstName] NVARCHAR(255) NULL, [lastName] NVARCHAR(255) NULL, [role] NVARCHAR(255) NULL, [subscribedModels] NVARCHAR(MAX) NULL, [supplierId] NVARCHAR(50) NULL, [phone] NVARCHAR(50) NULL, [updatedAt] DATETIMEOFFSET NOT NULL, PRIMARY KEY ([email]), FOREIGN KEY ([supplierId]) REFERENCES [Suppliers] ([id]) ON DELETE SET NULL);

Environment

  • Sequelize version: sequelize@6.35.2
  • Node.js version: v20.5.1
  • Database & Version: Microsoft SQL Azure (RTM) - 12.0.2000.8
  • Connector library & Version: mssql - ^10.0.1

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I will need guidance.
  • No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
  • No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.

Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.

@mitkonikolov mitkonikolov added pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug labels Jan 15, 2024
@ephys ephys added the v6 label Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug v6
Projects
None yet
Development

No branches or pull requests

2 participants