drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: Make one-to-one realtions NOT optional by default

Open
#5,560 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Feature hasn't been suggested before.

- [x] I have verified this feature I'm about to request hasn't been suggested before.

### Describe the enhancement you want to request

Version: 1.0.0-beta.20

The current behaviour is that a one-to-one relation is optional by default.
It's a little bit problematic. In my case (I think also in the real world), 99% of one-to-one relations are NOT optional. So it will be easier to define what IS optional instead.

Maybe the feature is not change default behaviour, just add option to define it.

Example:
```ts
const relations = defineRelations(schema, (r) => ({ ... }), { optionalDefault: false }).
```

Or take it from `schema`. If reference is not null - the relation is not optional.

Example:
```ts
export const persons = pgTable(
"persons",
{
id: integer().primaryKey(),
userId: uuid()
.notNull() // NOT optional relation
.references(() => user.id, { onDelete: "cascade", onUpdate: "cascade" }),
data: typedJsonb("data").notNull(),
},
);
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.