Nullable relational query?
In the following, shouldn't
It's telling me it's this type:
Shouldn't jobSeekerProfile be nullable?
This is the schema:
res.jobSeekerProfileres.jobSeekerProfile possibly be null? Basically what I want is to get the user - Include their jobSeekerProfile (if they have one). Currently, it seems to assume that jobSeekerProfile always exists for the userlet test = db.query.users.findFirst({
where: (users, { eq }) => eq(users.id, '1'),
with: {
jobSeekerProfile: true,
},
})
test.then((res) => {
if (res) {
res.jobSeekerProfile
}
})let test = db.query.users.findFirst({
where: (users, { eq }) => eq(users.id, '1'),
with: {
jobSeekerProfile: true,
},
})
test.then((res) => {
if (res) {
res.jobSeekerProfile
}
})It's telling me it's this type:
res: {
id: string;
name: string | null;
email: string;
emailVerified: Date | null;
image: string | null;
createdAt: Date;
updatedAt: Date;
jobSeekerProfile: {
id: string;
userId: string;
bio: string | null;
cvUrl: string | null;
};
}res: {
id: string;
name: string | null;
email: string;
emailVerified: Date | null;
image: string | null;
createdAt: Date;
updatedAt: Date;
jobSeekerProfile: {
id: string;
userId: string;
bio: string | null;
cvUrl: string | null;
};
}Shouldn't jobSeekerProfile be nullable?
This is the schema:
export const users = pgTable('users', {
id: text('id').notNull().primaryKey(),
name: text('name'),
email: text('email').notNull(),
emailVerified: timestamp('emailVerified', { mode: 'date' }),
image: text('image'),
createdAt: timestamp('createdAt', { mode: 'date' }).notNull(),
updatedAt: timestamp('updatedAt', { mode: 'date' }).notNull(),
})
export const userRelations = relations(users, ({ one }) => ({
jobSeekerProfile: one(jobSeekerProfiles, {
fields: [users.id],
references: [jobSeekerProfiles.userId],
}),
}))
export const jobSeekerProfiles = pgTable('jobSeekerProfiles', {
id: text('id').notNull().primaryKey(),
userId: text('userId')
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
bio: text('bio'),
cvUrl: text('cvUrl'),
})export const users = pgTable('users', {
id: text('id').notNull().primaryKey(),
name: text('name'),
email: text('email').notNull(),
emailVerified: timestamp('emailVerified', { mode: 'date' }),
image: text('image'),
createdAt: timestamp('createdAt', { mode: 'date' }).notNull(),
updatedAt: timestamp('updatedAt', { mode: 'date' }).notNull(),
})
export const userRelations = relations(users, ({ one }) => ({
jobSeekerProfile: one(jobSeekerProfiles, {
fields: [users.id],
references: [jobSeekerProfiles.userId],
}),
}))
export const jobSeekerProfiles = pgTable('jobSeekerProfiles', {
id: text('id').notNull().primaryKey(),
userId: text('userId')
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
bio: text('bio'),
cvUrl: text('cvUrl'),
})