mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03:00
Fix logic in finding relation for column in parseSupaTable
This commit is contained in:
1 parent
81d960cdf0
commit
c720b2885b
1 file changed
+22
-15
@@ -85,6 +85,8 @@ export function initTable(
|
||||
return { savedState: { sorts: savedState.sorts, filters: savedState.filters } }
|
||||
}
|
||||
|
||||
console.log('onInitTable', table)
|
||||
|
||||
const gridColumns = getGridColumns(table, {
|
||||
editable: props.editable,
|
||||
defaultWidth: props.gridProps?.defaultColumnWidth,
|
||||
@@ -189,29 +191,34 @@ export function parseSupaTable(data: {
|
||||
relationships: Dictionary<any>[]
|
||||
}): SupaTable {
|
||||
const { table, columns, primaryKeys, relationships } = data
|
||||
const supaColumns: SupaColumn[] = columns.map((x) => {
|
||||
|
||||
const supaColumns: SupaColumn[] = columns.map((column) => {
|
||||
const temp = {
|
||||
position: x.ordinal_position,
|
||||
name: x.name,
|
||||
defaultValue: x.default_value,
|
||||
dataType: x.data_type,
|
||||
format: x.format,
|
||||
position: column.ordinal_position,
|
||||
name: column.name,
|
||||
defaultValue: column.default_value,
|
||||
dataType: column.data_type,
|
||||
format: column.format,
|
||||
isPrimaryKey: false,
|
||||
isIdentity: x.is_identity,
|
||||
isGeneratable: x.identity_generation == 'BY DEFAULT',
|
||||
isNullable: x.is_nullable,
|
||||
isUpdatable: x.is_updatable,
|
||||
enum: x.enums,
|
||||
comment: x.comment,
|
||||
isIdentity: column.is_identity,
|
||||
isGeneratable: column.identity_generation == 'BY DEFAULT',
|
||||
isNullable: column.is_nullable,
|
||||
isUpdatable: column.is_updatable,
|
||||
enum: column.enums,
|
||||
comment: column.comment,
|
||||
targetTableSchema: null,
|
||||
targetTableName: null,
|
||||
targetColumnName: null,
|
||||
}
|
||||
const primaryKey = primaryKeys.find((pk) => pk.name == x.name)
|
||||
const primaryKey = primaryKeys.find((pk) => pk.name == column.name)
|
||||
temp.isPrimaryKey = !!primaryKey
|
||||
|
||||
const relationship = relationships.find((r) => {
|
||||
return r.source_column_name == x.name
|
||||
const relationship = relationships.find((relation) => {
|
||||
return (
|
||||
relation.source_schema === column.schema &&
|
||||
relation.source_table_name === column.table &&
|
||||
relation.source_column_name === column.name
|
||||
)
|
||||
})
|
||||
if (relationship) {
|
||||
temp.targetTableSchema = relationship.target_table_schema
|
||||
|
||||
Reference in new issue
Block a user