Offer foreign key for id_my_table (thanks to Kevujin)
This commit is contained in:
parent
021e1e319c
commit
c41c101aa3
|
@ -71,12 +71,14 @@ function loginDriver(driver) {
|
||||||
|
|
||||||
var added = '.', rowCount;
|
var added = '.', rowCount;
|
||||||
|
|
||||||
/** Escape string to use in regular expression
|
/** Check if val is equal to a-delimiter-b where delimiter is '_', '' or big letter
|
||||||
* @param string
|
* @param string
|
||||||
* @return string
|
* @param string
|
||||||
|
* @param string
|
||||||
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
function reEscape(s) {
|
function delimiterEqual(val, a, b) {
|
||||||
return s.replace(/[\[\]\\^$*+?.(){|}]/, '\\$&');
|
return (val == a + '_' + b || val == a + b || val == a + b.charAt(0).toUpperCase() + b.substr(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Escape string to use as identifier
|
/** Escape string to use as identifier
|
||||||
|
@ -94,33 +96,28 @@ function editingNameChange(field) {
|
||||||
var name = field.name.substr(0, field.name.length - 7);
|
var name = field.name.substr(0, field.name.length - 7);
|
||||||
var type = formField(field.form, name + '[type]');
|
var type = formField(field.form, name + '[type]');
|
||||||
var opts = type.options;
|
var opts = type.options;
|
||||||
var table = reEscape(field.value);
|
|
||||||
var column = '';
|
|
||||||
var match;
|
|
||||||
if ((match = /(.+)_(.+)/.exec(table)) || (match = /(.*[a-z])([A-Z].*)/.exec(table))) { // limited to single word columns
|
|
||||||
table = match[1];
|
|
||||||
column = match[2];
|
|
||||||
}
|
|
||||||
var plural = '(?:e?s)?';
|
|
||||||
var tabCol = table + plural + '_?' + column;
|
|
||||||
var re = new RegExp('(^' + idfEscape(table + plural) + '`' + idfEscape(column) + '$' // table_column
|
|
||||||
+ '|^' + idfEscape(tabCol) + '`' // table
|
|
||||||
+ '|^' + idfEscape(column + plural) + '`' + idfEscape(table) + '$' // column_table
|
|
||||||
+ ')|`' + idfEscape(tabCol) + '$' // column
|
|
||||||
, 'i');
|
|
||||||
var candidate; // don't select anything with ambiguous match (like column `id`)
|
var candidate; // don't select anything with ambiguous match (like column `id`)
|
||||||
|
var val = field.value;
|
||||||
for (var i = opts.length; i--; ) {
|
for (var i = opts.length; i--; ) {
|
||||||
if (!/`/.test(opts[i].value)) { // common type
|
var match = /(.+)`(.+)/.exec(opts[i].value);
|
||||||
if (i == opts.length - 2 && candidate && !match[1] && name == 'fields[1]') { // single target table, link to column, first field - probably `id`
|
if (!match) { // common type
|
||||||
return false;
|
if (candidate && i == opts.length - 2 && val == opts[candidate].value.replace(/.+`/, '') && name == 'fields[1]') { // single target table, link to column, first field - probably `id`
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (match = re.exec(opts[i].value)) {
|
var table = match[1];
|
||||||
if (candidate) {
|
var column = match[2];
|
||||||
return false;
|
var tables = [ table, table.replace(/s$/, ''), table.replace(/es$/, '') ];
|
||||||
|
for (var j=0; j < tables.length; j++) {
|
||||||
|
table = tables[j];
|
||||||
|
if (val == column || val == table || delimiterEqual(val, table, column) || delimiterEqual(val, column, table)) {
|
||||||
|
if (candidate) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
candidate = i;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
candidate = i;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (candidate) {
|
if (candidate) {
|
||||||
|
|
Loading…
Reference in a new issue