Skip to content
11 changes: 8 additions & 3 deletions packages/drizzle/src/schema/traverseFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,13 @@ export const traverseFields = ({
},
}

const baseForeignKeys: Record<string, RawForeignKey> = {
_parentIdFk: {
// Skip creating a parent_id foreign key for blocks that are shared across collections (have a custom dbName)
const hasCustomDbName = block.dbName !== undefined && block.dbName !== null
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a more concise nullish coalescing check. The condition can be simplified to block.dbName != null which checks for both undefined and null in a single comparison.

Suggested change
const hasCustomDbName = block.dbName !== undefined && block.dbName !== null
const hasCustomDbName = block.dbName != null

Copilot uses AI. Check for mistakes.
const shouldSkipForeignKey = hasCustomDbName

const baseForeignKeys: Record<string, RawForeignKey> = {}
if (!shouldSkipForeignKey) {
baseForeignKeys._parentIdFk = {
name: `${blockTableName}_parent_id_fk`,
columns: ['_parentID'],
foreignColumns: [
Expand All @@ -461,7 +466,7 @@ export const traverseFields = ({
},
],
onDelete: 'cascade',
},
}
}

const isLocalized =
Expand Down
Loading