Ꚃimon
Ꚃimon
Explore posts from servers
DTDrizzle Team
Created by Ꚃimon on 9/13/2023 in #help
Cannot read properties of undefined (reading 'referencedTable')
My bad - it was trying to query some old relation
7 replies
DTDrizzle Team
Created by Ꚃimon on 9/13/2023 in #help
Cannot read properties of undefined (reading 'referencedTable')
Well I'm not quite sure which query is triggering this tbh
7 replies
DTDrizzle Team
Created by Ꚃimon on 9/13/2023 in #help
Cannot read properties of undefined (reading 'referencedTable')
Probably related to the relations somehow?
7 replies
DTDrizzle Team
Created by Ꚃimon on 9/13/2023 in #help
Cannot read properties of undefined (reading 'referencedTable')
//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),
}))
7 replies
DTDrizzle Team
Created by Ꚃimon on 9/13/2023 in #help
Cannot read properties of undefined (reading 'referencedTable')
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],
}),
}))
7 replies
DTDrizzle Team
Created by daniel on 6/11/2023 in #help
InferModel including relations?
Issue is that this will give you the wrong typehints if you're only selecting certain columns instead of all of them
16 replies
DTDrizzle Team
Created by daniel on 6/11/2023 in #help
InferModel including relations?
@chronicstone You can get the returntype of the function where you fetch the data and do the following
export type InitialPostsType = NonNullable<
Awaited<ReturnType<typeof getDataFunction>>
>
export type InitialPostsType = NonNullable<
Awaited<ReturnType<typeof getDataFunction>>
>
16 replies
DTDrizzle Team
Created by Ꚃimon on 8/9/2023 in #help
Nullable relational query?
So when should you be defining the fields and references?
15 replies
DTDrizzle Team
Created by Ꚃimon on 8/9/2023 in #help
Nullable relational query?
Oh! That did it. Not sure I understand the relations table then 😮
15 replies