Creating multiple `o2m` realationships to the same FK should be forbidden
- Dominant language
- TypeScript
- Stars
- 37.9k
- Forks
- 4.9k
- Avg merge
- 3d 23h
- Merged PRs (30d)
- 37
Description
## Preface
Hi,
I wanted to have a way for users to have multiple phone/email contacts in my app so i added a table : `user_contact` with fields such as status, type (phone,email), value etc and added a one to many relationship to this table on `directus_users`. This resulted in App being unusable As shown in screenshot below.
## To Reproduce
- Create a new data-model : `user_contact`
- Add these fields :
| Field Name | Type | Notes |
|--------------------|--------------|----------------------------------------|
| id | uuid (PK) | |
|status | Dropdown | ENUM : 'verified', 'pending', 'disabled'|
| user | M2O | Reference to directus_users |
| type | Dropdown | ENUM: 'email', 'phone' |
| value | string | The email or phone number |
| verified_at | datetime | When verification occurred |
| created_at | datetime | |
| updated_at | datetime | |
- Now go to `directus_users` and add Two New Fields `primary_email` and `primary_phone`.
- Use One to many relationship for both fields to the `user_contact` table with `user` as FK.
- Check `value has to be unique` in advanced field config to make it a O2O relation.
- Add filtering as follows :
`type equals phone/email`; whichever is appropriate for that particular field.
- Save and reload the page and the app will surely break. If not, then :
- Edit filter to also have `AND -> status equals verified`
### Directus Version
v11.8.0
### Hosting Strategy
Self-Hosted (Docker Image)
### Database
postgis:15-3.4
Contributor guide
Research direction
The issue names no files, tests, or code entry points. Start by reproducing the relationship setup in Directus v11.8.0 with the described user_contact fields and filters, then trace where the relationship configuration is accepted and rendered. Done means the conflicting relationships are rejected or handled without making the app unusable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, typescript
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100