rqb v2: `with` is always nullable

I'm trying to migrate to rqb v2, but it seems that related tables in
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


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)
    })
);


Note that addressId is .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(),
    },
}));


Is this a bug in rqb v2 or is my code missing something?
Was this page helpful?