Allow field default to reference other fields
See original GitHub issueProblem
I have a model where there is the concept of a unique name
and a displayName
. Think GitHub organizations. I would like to encode in the model that the default for the displayName
field is name
field.
Suggested solution
An expression that references another non-nullable field whose type is the same.
model Workspace {
kind WorkspaceKind @default(workspace)
id String @id @default(uuid())
name String @unique
displayName String @default(field(name)) // <-- example
members User[]
}
Alternatives
It is easy to encode this at the application layer.
Additional context
This is a NTH (nice to have). The theme is encoding as much as possible at the database layer so that the application layer is easier to reason about.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Reference Object fields when setting default values
When setting a default value for any field on a specific object, I cannot reference that object within the formula. However this can...
Read more >Set default values for fields or controls - Microsoft Support
Set a default value Select the field that you want to change. On the General tab, type a value in the Default Value...
Read more >How to pass default value to custom field to reference other field
I have an custom object name PowerPlantIntroduce__c and have two fields: The first one is pictureUrl__c (Data Type: URL. Used to save picture's ......
Read more >How to set default value of a reference field base... - ServiceNow
I have a reference variable for location of the user and another reference variable within the form to display the 'requested for' user....
Read more >Django Model Field Default Based Off Another Field in Same ...
Is this possible in Django, having a callable function give a default to some field based on the value of another field?
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I had a quick look whether the new arbitrary sql in
@default(dbgenerated())
would allow that. It seems that Postgres and Mysql do not directly support that in the default definition. So we’d indeed need a completely new feature for this.Hi guys, is this something you decided to progress? I have two fields:
endTime: DateTime
(which would be some day in the future)24HoursAheadOfEndTime: DateTime @default(dbgenerated("NOW() + INTERVAL '1 DAY'"))
And I would like to replace NOW() with endTime field, is this possible at all or not?