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

Enhancement: Nullable 1-1 Relations #944

Merged
merged 1 commit into from
Sep 22, 2023

Conversation

the-mediocre-dev
Copy link
Contributor

@the-mediocre-dev the-mediocre-dev commented Jul 17, 2023

Proposed changes

It is not uncommon to design relations between tables with a nullable foreign key, signalling a 0-1 relation rather than a 1-1. While lucid will allow this, the typings do not, meaning that downstream from the models the typings cannot be trusted. This change adds Typescript support for nullable HasOne and BelongsTo relations, as such:

@hasOne(() => Profile)
public profile: HasOne<typeof Profile> | null

Discussed in:

Types of changes

Relationship type changes

Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added necessary documentation (if appropriate)

Sorry, something went wrong.

…lations (hasOne and belongsTo)

It is not uncommon to design relations between tables with a nullable foreign key, signalling a 0-1
relation rather than a 1-1. While lucid will allow this, the typings do not, meaning that downstream
from the models the typings cannot be trusted. This change adds support for this.
@stale
Copy link

stale bot commented Sep 16, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Abandoned Dropped and not into consideration label Sep 16, 2023
@RomainLanz RomainLanz removed the Status: Abandoned Dropped and not into consideration label Sep 18, 2023
@RomainLanz RomainLanz added Semver: Patch A bug fix Status: Review Needed Review from the core team is required before moving forward labels Sep 18, 2023
@RomainLanz RomainLanz merged commit b7ec9d4 into adonisjs:develop Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Semver: Patch A bug fix Status: Review Needed Review from the core team is required before moving forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants