Create slug based on title field.

I currently have a product schema that has title field that is a nonNull text. I want to create a slug that is automatically generated. My current approach to this is using the .$defaultFn((title) => createSlug(title)) but I am struggling to find a way to reference title in the defaultFn. Is there some way to do this?
3 Replies
Riven
Riven8mo ago
I am having this exact issue as well. Scoured the project; $default and $onUpdate don't pass any parameters
xxxxx
xxxxxOP8mo ago
the quick hack i've found is you can create a slug when you are inserting an object to the database (create slug client side and then add it to the db) but this is not an ideal solution
Riven
Riven8mo ago
yeah, it's a derived value, so it shouldn't be in the client logic (ideally), in the same way that there's tools to manage createdAt/updatedAt
Want results from more Discord servers?
Add your server