Ā© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
8 replies
rykuno

Optional/Default value for Relational `Extras`

I have a couple cases where a default/optional value for "extras" in the relational query builder could come in handy. I only really want to run this if the user is logged in. ATM I have the following solution

        extras(fields, operators) {
            return {
                authedUserTicketId:
                    sql<string>`(SELECT (ticket_id) from ${members} where event_id = ${
                        fields.id
                    } and user_id = ${authedUser?.user.id || null})`.as(
                        'authed_user_membership'
                    )
            };
        },
        extras(fields, operators) {
            return {
                authedUserTicketId:
                    sql<string>`(SELECT (ticket_id) from ${members} where event_id = ${
                        fields.id
                    } and user_id = ${authedUser?.user.id || null})`.as(
                        'authed_user_membership'
                    )
            };
        },


If there is no auth user it just sets the user_id to null but its not exactly ideal. Is there any plans or current way to optionally add this statement within the same return block?
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Bug: Count in Extras (Relational)
Drizzle TeamDTDrizzle Team / help
9mo ago
Relational query `extras` are not properly adding sql
Drizzle TeamDTDrizzle Team / help
3y ago
Invalid default value for 'updatedAt'
Drizzle TeamDTDrizzle Team / help
3y ago
define default value for array
Drizzle TeamDTDrizzle Team / help
3y ago