Skip to content

test: add regression for nullable hasMany onDelete behavior#18174

Open
PiyushInt wants to merge 1 commit into
sequelize:mainfrom
PiyushInt:feature
Open

test: add regression for nullable hasMany onDelete behavior#18174
PiyushInt wants to merge 1 commit into
sequelize:mainfrom
PiyushInt:feature

Conversation

@PiyushInt
Copy link
Copy Markdown

@PiyushInt PiyushInt commented Mar 28, 2026

This PR addresses #18172 for the v7 codebase.

In v7, the behavior for a nullable foreign key created via hasMany is already correct: when the FK column is nullable (i.e. allowNull is not explicitly set to false), the generated constraint defaults to ON DELETE SET NULL.

This change adds a regression test to lock in that behavior:

packages/core/test/unit/associations/has-many.test.ts
Verifies that when Foo.userId is defined without allowNull: false and User.hasMany(Foo, { foreignKey: 'userId' }) is used, Foo.getAttributes().userId has:
allowNull not forced to false
onDelete === 'SET NULL'
No runtime code changes were necessary; this is a test-only change to prevent regressions and to document the intended behavior for nullable 1:n associations.

Summary by CodeRabbit

  • Tests
    • Added test case verifying default cascade delete behavior for nullable foreign key relationships in multi-table associations.

@PiyushInt PiyushInt requested a review from a team as a code owner March 28, 2026 13:49
@PiyushInt PiyushInt requested review from WikiRik and sdepold March 28, 2026 13:49
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c39ec22a-dae4-4ebd-b8b5-04eb5c714021

📥 Commits

Reviewing files that changed from the base of the PR and between df4a631 and 375ac08.

📒 Files selected for processing (1)
  • packages/core/test/unit/associations/has-many.test.ts

📝 Walkthrough

Walkthrough

Added a new test case to verify that nullable foreign key fields default to onDelete: 'SET NULL' behavior when the allowNull attribute is omitted from the field definition during association configuration.

Changes

Cohort / File(s) Summary
Test Addition
packages/core/test/unit/associations/has-many.test.ts
New test case verifying default onDelete behavior for nullable foreign keys without explicit allowNull attribute in hasMany associations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A test hops in, so neat and bright,
Checking nullable keys set just right—
When onDelete meets SET NULL grace,
Foreign keys find their proper place! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a regression test for nullable hasMany onDelete behavior, which matches the file changes and PR objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.16.5)
packages/core/test/unit/associations/has-many.test.ts

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

�[1m Loading rules from local config...�[0m


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant