这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions console/src/components/Services/Data/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ const findFKConstraint = (curTable, column) => {
);
};

const findOppFKConstraint = (curTable, column) => {
const fkConstraints = curTable.opp_foreign_key_constraints;
return fkConstraints.find(
fk =>
Object.keys(fk.column_mapping).length === column.length &&
Object.keys(fk.column_mapping).join(',') === column.join(',')
);
};

export const findTableFromRel = (schemas, curTable, rel) => {
let rTable = null;
let rSchema = 'public';
Expand Down Expand Up @@ -132,7 +141,6 @@ export const findAllFromRel = (schemas, curTable, rel) => {
// for object relationship
if (rel.rel_type === 'object') {
relMeta.lcol = [foreignKeyConstraintOn];

const fkc = findFKConstraint(curTable, relMeta.lcol);
if (fkc) {
relMeta.rTable = fkc.ref_table;
Expand All @@ -152,12 +160,7 @@ export const findAllFromRel = (schemas, curTable, rel) => {
relMeta.rTable = rTableConfig;
relMeta.rSchema = 'public';
}

const rtableSchema = schemas.find(
x =>
x.table_name === relMeta.rTable && x.table_schema === relMeta.rSchema
);
const rfkc = findFKConstraint(rtableSchema, relMeta.rcol);
const rfkc = findOppFKConstraint(curTable, relMeta.rcol);
relMeta.lcol = [rfkc.column_mapping[relMeta.rcol]];
}
}
Expand Down