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

[FEATURE]: Optional One-to-One Relation #1066

Open
413n opened this issue Aug 17, 2023 · 7 comments
Open

[FEATURE]: Optional One-to-One Relation #1066

413n opened this issue Aug 17, 2023 · 7 comments
Assignees
Labels
enhancement New feature or request priority Will be worked on next rqb relational queries

Comments

@413n
Copy link

413n commented Aug 17, 2023

Describe what you want

Currently it's possible to define only a One-to-One relation (https://orm.drizzle.team/docs/rqb#one-to-one) but in the types, the value returned will never be undefined or null.
In my use case I would like to define a One-to-One relation that could be optional.
Is there a solution? Is this even possible?

@413n 413n added the enhancement New feature or request label Aug 17, 2023
@tarekwiz
Copy link

tarekwiz commented Nov 9, 2023

+1. I think the types should at least be T | undefined instead of T

@foodornt
Copy link

Any idea why it's not already nullable?

@jadamduff
Copy link

+1

@agulencina96
Copy link

Any update on this?

@amirfakhrullah
Copy link

Hey, do we have an update for this?

@j-fdion
Copy link

j-fdion commented Jun 7, 2024

Yes, this one is a must have!

@ghardin1314
Copy link

I think you can accomplish with this comment

https://www.answeroverflow.com/m/1126473676804599881

i.e. only put the fields and references on the one who knows about the other. My example oprganization.shopIfyIntegration is nullable

export const shopifyIntegrationRelations = relations(
  shopifyIntegrations,
  ({ one }) => ({
    organization: one(organizations, {
      fields: [shopifyIntegrations.organizationId],
      references: [organizations.id],
    }),
  }),
);


export const organizationRelations = relations(
  organizations,
  ({ one, many }) => ({
    shopifyIntegration: one(shopifyIntegrations),
  }),
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority Will be worked on next rqb relational queries
Projects
Status: Todo
Development

No branches or pull requests

10 participants