drizzle-team / drizzle-team/drizzle-orm

[BUG]: Relations cannot have a 'constructor' key

Open Beginner friendly
#6,076 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] I have verified that the bug I'm about to report hasn't been filed before.

### What version of `drizzle-orm` are you using?

1.0.0-rc.4

### What version of `drizzle-kit` are you using?

1.0.0-rc.4

### Other packages

_No response_

### Describe the Bug

Relations uses `relationFieldName in tableConfig.table[TableColumns]` to check for column collisions, though this will always fail for `constructor`

```ts
export const relations = defineRelations(s, (r) => ({
results: {
event: r.one.events({
from: r.results.eventId,
to: r.events.id,
optional: false,
}),
driver: r.one.drivers({
from: r.results.driverId,
to: r.drivers.id,
optional: false,
}),
constructor: r.one.constructors({
// results does not have a constructor column
from: r.results.constructorId,
to: r.constructors.id,
optional: true,
}),
},
}));
```

```
relations -> results: { constructor: r.one.constructors(...) }: relation name collides with column "constructor" of table "results"
```

Contributor guide

Open the contributing guide

Research direction

Start at the defineRelations entry point and inspect the relation-field collision check described in the issue, especially its handling of the `constructor` key. Add regression coverage showing that a relation named `constructor` is accepted when no same-named column exists, while genuine column collisions remain rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.