© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•9mo ago•
4 replies
lsof

rqb v2: `with` is always nullable

I'm trying to migrate to rqb v2, but it seems that related tables in
with
with
are always nullable.

Here's my query:
const organizations = await db.query.organization.findMany({
    with: {
        address: true
    }
});
// organizations[0].address should NOT be nullable,
// but according to TypeScript, it is
const organizations = await db.query.organization.findMany({
    with: {
        address: true
    }
});
// organizations[0].address should NOT be nullable,
// but according to TypeScript, it is


My schema:

export const address = pgTable("address", (t) => ({
    id: t.integer().primaryKey().generatedAlwaysAsIdentity()
}));
export const organization = pgTable("organization", (t) => ({
    id: t.integer().primaryKey().generatedAlwaysAsIdentity(),
    addressId: t
        .integer()
        .notNull() // <-- in rqb v1, this was enough
        .references(() => address.id)
    })
);
export const address = pgTable("address", (t) => ({
    id: t.integer().primaryKey().generatedAlwaysAsIdentity()
}));
export const organization = pgTable("organization", (t) => ({
    id: t.integer().primaryKey().generatedAlwaysAsIdentity(),
    addressId: t
        .integer()
        .notNull() // <-- in rqb v1, this was enough
        .references(() => address.id)
    })
);


Note that
addressId
addressId
is
.notNull()
.notNull()
. These are my relations:

// Relations
export const relations = defineRelations(schema, (r) => ({
    organization: {
        address: r.one.address({
            from: r.organization.addressId,
            to: r.address.id,
        }),
    },
    address: {
        organizations: r.many.organization(),
    },
}));
// Relations
export const relations = defineRelations(schema, (r) => ({
    organization: {
        address: r.one.address({
            from: r.organization.addressId,
            to: r.address.id,
        }),
    },
    address: {
        organizations: r.many.organization(),
    },
}));


Is this a bug in rqb v2 or is my code missing something?
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

using rqb with pgSchema
Drizzle TeamDTDrizzle Team / help
13mo ago
PostgreSQL RQB truncation
Drizzle TeamDTDrizzle Team / help
3y ago
Why fields with default value is nullable
Drizzle TeamDTDrizzle Team / help
2y ago
How to use inner join with rqb?
Drizzle TeamDTDrizzle Team / help
3y ago