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

Feat: optional where clause in relations #1451

Open
wants to merge 11 commits into
base: beta
Choose a base branch
from

Conversation

Angelelz
Copy link
Collaborator

@Angelelz Angelelz commented Nov 1, 2023

This PR will close #1437, and will close #1051, will address part of #674 and part of #821.

Upon successful merging of this PR, a new where option will be added to the relation configuration. The most obvious use case is to better support for polymorphic associations when you'll like to associate a table with another one, only when a condition is met:

export const usersRelations = relations(users, ({ many }) => ({
  comments: many(comments, {
    where: eq(comments.commentType, 'user')
  }),
}));

The new where configuration option is also available in the one relation.
Please note that adding a where condition in the one relation will mark that field as nullable even if the column is not nullable, as we don't have a way of knowing at compile time if any row will be returned from the DB.

@Angelelz Angelelz force-pushed the feat-optional-where-in-relations branch 2 times, most recently from d9fc213 to cd3f210 Compare November 10, 2023 02:25
@raikusy
Copy link

raikusy commented Nov 22, 2023

Any update on this?

@andrewdoro
Copy link

Hey just saw this, it would be really nice to have this merged

@Angelelz Angelelz force-pushed the feat-optional-where-in-relations branch from 746acd8 to cfa1c1d Compare December 27, 2023 02:26
@TaylorFacen
Copy link

Hi, this looks amazing. Would love to have this merged in.

@ryanimpey
Copy link

Is there any update on this? Would love to have this in the next release!

@faribauc
Copy link

+1 Yes please!

@kenn
Copy link

kenn commented Jun 1, 2024

Folks, relational API v2 is discussed at #2316

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.

8 participants