Ensure that the referenced table should be displayed on foreign key constraints. Fixes #5530

pull/33/head
Yogesh Mahajan 2020-07-02 15:56:32 +05:30 committed by Akshay Joshi
parent 8b10315e2a
commit 1802f8a3f8
4 changed files with 52 additions and 7 deletions

View File

@ -22,6 +22,7 @@ Bug fixes
| `Issue #3851 <https://redmine.postgresql.org/issues/3851>`_ - Add proper indentation to the code while generating functions, procedures, and trigger functions.
| `Issue #4235 <https://redmine.postgresql.org/issues/4235>`_ - Fixed tab indent issue on a selection of lines is deleting the content when 'use spaces == true' in the preferences.
| `Issue #5530 <https://redmine.postgresql.org/issues/5530>`_ - Ensure that the referenced table should be displayed on foreign key constraints.
| `Issue #5621 <https://redmine.postgresql.org/issues/5621>`_ - Remove extra brackets from reverse engineering SQL of RLS Policy.
| `Issue #5630 <https://redmine.postgresql.org/issues/5630>`_ - Fixed an issue where installation of pgadmin4 not working on 32-bit Windows.
| `Issue #5631 <https://redmine.postgresql.org/issues/5631>`_ - Fixed 'cant execute empty query' issue when remove the value of 'USING' or 'WITH CHECK' option of RLS Policy.

View File

@ -51,11 +51,15 @@ define('pgadmin.node.foreign_key', [
},
schema: [{
id: 'local_column', label: gettext('Local'), type:'text', editable: false,
cellHeaderClasses: 'width_percent_50', cell:'string',
cellHeaderClasses: 'width_percent_35', cell:'string',
headerCell: Backgrid.Extension.CustomHeaderCell,
},{
id: 'referenced', label: gettext('Referenced'), type: 'text', editable: false,
cell:'string', cellHeaderClasses: 'width_percent_50',
cell:'string', cellHeaderClasses: 'width_percent_35',
headerCell: Backgrid.Extension.CustomHeaderCell,
},{
id: 'references_table_name', label: gettext('Referenced Table'), type: 'text', editable: false,
cell:'string', cellHeaderClasses: 'width_percent_30',
headerCell: Backgrid.Extension.CustomHeaderCell,
}],
});
@ -203,6 +207,9 @@ define('pgadmin.node.foreign_key', [
url = self.field.get('url') || self.defaults.url,
m = self.model,
tid = m.get('references');
// Store name for selected table
var a = $('select[name="references"]').find(':selected').text();
this.model.set('references_table_name', a,{silent: true});
// Clear any existing value before setting new options.
m.set(self.field.get('name'), null, {silent: true});
@ -267,7 +274,7 @@ define('pgadmin.node.foreign_key', [
headerDefaults = {local_column: null,
references: null,
referenced:null},
gridCols = ['local_column', 'references', 'referenced'];
gridCols = ['local_column', 'references', 'referenced','references_table_name'];
if ((!self.model.isNew() && _.isUndefined(self.model.handler)) ||
(_.has(self.model, 'handler') &&
@ -689,6 +696,7 @@ define('pgadmin.node.foreign_key', [
defaults: {
name: undefined,
reftab: undefined,
oid: undefined,
is_sys_obj: undefined,
comment: undefined,
@ -712,7 +720,7 @@ define('pgadmin.node.foreign_key', [
schema: [{
id: 'name', label: gettext('Name'), type: 'text',
mode: ['properties', 'create', 'edit'], editable:true,
headerCell: Backgrid.Extension.CustomHeaderCell, cellHeaderClasses: 'width_percent_50',
headerCell: Backgrid.Extension.CustomHeaderCell, cellHeaderClasses: 'width_percent_30',
},{
id: 'oid', label: gettext('OID'), cell: 'string',
type: 'text' , mode: ['properties'],
@ -898,11 +906,45 @@ define('pgadmin.node.foreign_key', [
// We can't update columns of existing foreign key.
return !m.isNew();
},
},{
id: 'references_table_name', label: gettext('Referenced Table'),
type: 'text', group: gettext('Columns'),
node: 'foreign_key', editable: false,visible:false,
cellHeaderClasses: 'width_percent_30',
cell: Backgrid.StringCell.extend({
initialize: function() {
Backgrid.StringCell.prototype.initialize.apply(this, arguments);
var self = this,
collection = this.model.get('columns');
self.model.get('columns').on('pgadmin:columns:updated', function() {
self.render.apply(self);
});
self.listenTo(collection, 'add', self.render);
self.listenTo(collection, 'remove', self.render);
},
formatter: {
fromRaw: function (rawValue,model,) {
var remote_tables = [],
m = model.get('columns');
if (m.length > 0) {
m.each(function(col){
remote_tables.push(col.get('references_table_name'));
});
return remote_tables;
}
},
toRaw: function (val) { return val; },
},
render: function() {
return Backgrid.StringCell.prototype.render.apply(this, arguments);
},
}),
},{
id: 'columns', label: gettext('Columns'),
type: 'collection', group: gettext('Columns'),
node: 'foreign_key', editable: false, headerCell: Backgrid.Extension.CustomHeaderCell,
cellHeaderClasses: 'width_percent_50',
cellHeaderClasses: 'width_percent_30',
cell: Backgrid.StringCell.extend({
initialize: function() {
Backgrid.StringCell.prototype.initialize.apply(this, arguments);

View File

@ -69,7 +69,9 @@ def get_foreign_keys(conn, tid, fkid=None, template_path=None):
for row in res['rows']:
columns.append({"local_column": row['conattname'],
"references": fk['confrelid'],
"referenced": row['confattname']})
"referenced": row['confattname'],
"references_table_name":
fk['refnsp'] + '.' + fk['reftab']})
cols.append(row['conattname'])
fk['columns'] = columns

View File

@ -698,7 +698,7 @@ define('pgadmin.node.table', [
return true;
},
columns : ['name', 'columns'],
columns : ['name', 'columns','references_table_name'],
canAddRow: function(m) {
// User can only add if there is at least one column with name.
var columns = m.get('columns');