Cannot read properties of undefined (reading 'referencedTable')

Seemingly getting this error out of nowhere. I believe it's related to the relations I defined, but can't quite figure out what is causing it specifically.
3 Replies
Ꚃimon
ꚂimonOP15mo ago
These are the recent additions that introduced the bugs:
// JobPosting
import { relations } from 'drizzle-orm'
import {
pgTable,
uuid,
timestamp,
text,
boolean,
integer,
index,
} from 'drizzle-orm/pg-core'
import { companyProfile } from './company'
import { hoursEnum, categoryEnum } from './enums'
import { location } from './location'

export const jobPosting = pgTable(
'jobPosting',
{
id: uuid('id').notNull().primaryKey().defaultRandom(),
createdAt: timestamp('createdAt', { mode: 'date' }).notNull().defaultNow(),
updatedAt: timestamp('updatedAt', { mode: 'date' }).notNull().defaultNow(),
companyId: uuid('companyId')
.references(() => companyProfile.id, {
onDelete: 'cascade',
})
.notNull(),
slug: text('slug').unique(),
applicationEmail: text('applicationEmail'),
applicationUrl: text('applicationUrl'),
positionTitle: text('positionTitle').notNull(),
positionDescription: text('positionDescription').notNull(),
positionHours: hoursEnum('positionHours'),
positionCategory: categoryEnum('positionCategory'),
stripeId: text('stripeId').unique(),
isPublished: boolean('isPublished').default(false),
expiration: timestamp('expiration', { mode: 'date' }),
isDefaultHighlighted: boolean('isDefaultHighlighted').default(false),
isCustomHighlighted: boolean('isCustomHighlighted').default(false),
customHighlightColor: text('customHighlightColor'),
locationId: text('locationId').references(() => location.id),
shouldBePresentInLocation: boolean('shouldBePresentInLocation').default(
false
),
stickyExpirationDate: timestamp('stickyExpirationDate', { mode: 'date' }),
isRemote: boolean('isRemote').default(false),
isBackfilled: boolean('isBackfilled').default(false),
backfillSource: text('backfillSource'),
salaryFrom: integer('salaryFrom'),
salaryTo: integer('salaryTo'),
salaryCurrency: text('salaryCurrency'),
salaryInterval: text('salaryInterval'),
},
(table) => {
return {
slugIdx: index('slug_idx').on(table.slug),
stickyExpirationDateIdx: index('sticky_expiration_date_idx')
.on(table.stickyExpirationDate)
.desc()
.nullsLast(),
createdAtIdx: index('created_at_idx').on(table.createdAt),
positionHoursIdx: index('position_hours_idx').on(table.positionHours),
positionCategoryIdx: index('position_category_idx').on(
table.positionCategory
),
}
}
)

export const jobPostingRelations = relations(jobPosting, ({ one }) => ({
companyProfile: one(companyProfile, {
fields: [jobPosting.companyId],
references: [companyProfile.id],
}),
location: one(location, {
fields: [jobPosting.locationId],
references: [location.id],
}),
}))
// JobPosting
import { relations } from 'drizzle-orm'
import {
pgTable,
uuid,
timestamp,
text,
boolean,
integer,
index,
} from 'drizzle-orm/pg-core'
import { companyProfile } from './company'
import { hoursEnum, categoryEnum } from './enums'
import { location } from './location'

export const jobPosting = pgTable(
'jobPosting',
{
id: uuid('id').notNull().primaryKey().defaultRandom(),
createdAt: timestamp('createdAt', { mode: 'date' }).notNull().defaultNow(),
updatedAt: timestamp('updatedAt', { mode: 'date' }).notNull().defaultNow(),
companyId: uuid('companyId')
.references(() => companyProfile.id, {
onDelete: 'cascade',
})
.notNull(),
slug: text('slug').unique(),
applicationEmail: text('applicationEmail'),
applicationUrl: text('applicationUrl'),
positionTitle: text('positionTitle').notNull(),
positionDescription: text('positionDescription').notNull(),
positionHours: hoursEnum('positionHours'),
positionCategory: categoryEnum('positionCategory'),
stripeId: text('stripeId').unique(),
isPublished: boolean('isPublished').default(false),
expiration: timestamp('expiration', { mode: 'date' }),
isDefaultHighlighted: boolean('isDefaultHighlighted').default(false),
isCustomHighlighted: boolean('isCustomHighlighted').default(false),
customHighlightColor: text('customHighlightColor'),
locationId: text('locationId').references(() => location.id),
shouldBePresentInLocation: boolean('shouldBePresentInLocation').default(
false
),
stickyExpirationDate: timestamp('stickyExpirationDate', { mode: 'date' }),
isRemote: boolean('isRemote').default(false),
isBackfilled: boolean('isBackfilled').default(false),
backfillSource: text('backfillSource'),
salaryFrom: integer('salaryFrom'),
salaryTo: integer('salaryTo'),
salaryCurrency: text('salaryCurrency'),
salaryInterval: text('salaryInterval'),
},
(table) => {
return {
slugIdx: index('slug_idx').on(table.slug),
stickyExpirationDateIdx: index('sticky_expiration_date_idx')
.on(table.stickyExpirationDate)
.desc()
.nullsLast(),
createdAtIdx: index('created_at_idx').on(table.createdAt),
positionHoursIdx: index('position_hours_idx').on(table.positionHours),
positionCategoryIdx: index('position_category_idx').on(
table.positionCategory
),
}
}
)

export const jobPostingRelations = relations(jobPosting, ({ one }) => ({
companyProfile: one(companyProfile, {
fields: [jobPosting.companyId],
references: [companyProfile.id],
}),
location: one(location, {
fields: [jobPosting.locationId],
references: [location.id],
}),
}))
//location
import { pgTable, text, numeric, uuid } from 'drizzle-orm/pg-core'
import { jobPosting } from './jobposting'
import { relations } from 'drizzle-orm'

export const location = pgTable('location', {
id: text('placeId').notNull().primaryKey(),
lat: numeric('latitude'),
lng: numeric('longitude'),
country: text('country').notNull(),
countryShort: text('countryCode').notNull(),
administrativeAreaLevel1: text('administrativeAreaLevel1'),
administrativeAreaLevel1Short: text('administrativeAreaLevel1Short'),
locality: text('locality'),
localityShort: text('localityShort'),
sublocality: text('sublocality'),
})

export const locationRelations = relations(location, ({ many }) => ({
jobPosting: many(jobPosting),
}))
//location
import { pgTable, text, numeric, uuid } from 'drizzle-orm/pg-core'
import { jobPosting } from './jobposting'
import { relations } from 'drizzle-orm'

export const location = pgTable('location', {
id: text('placeId').notNull().primaryKey(),
lat: numeric('latitude'),
lng: numeric('longitude'),
country: text('country').notNull(),
countryShort: text('countryCode').notNull(),
administrativeAreaLevel1: text('administrativeAreaLevel1'),
administrativeAreaLevel1Short: text('administrativeAreaLevel1Short'),
locality: text('locality'),
localityShort: text('localityShort'),
sublocality: text('sublocality'),
})

export const locationRelations = relations(location, ({ many }) => ({
jobPosting: many(jobPosting),
}))
Probably related to the relations somehow?
Angelelz
Angelelz15mo ago
Can you show the query you're trying to run?
Ꚃimon
ꚂimonOP15mo ago
Well I'm not quite sure which query is triggering this tbh My bad - it was trying to query some old relation
Want results from more Discord servers?
Add your server