Created
February 10, 2011 22:37
-
-
Save iNecas/821510 to your computer and use it in GitHub Desktop.
Convention foreign keys: plugin for Adminer (http://www.adminer.org)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** Convention foreign keys: plugin for Adminer | |
* Links for foreign keys by convention user_id => users.id. Useful for Ruby On Rails like standard schema conventions. | |
* @author Ivan Nečas, @inecas | |
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 | |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other) | |
*/ | |
class ConventionForeignKeys { | |
function foreignKeys($table) { | |
$ret = array(); | |
foreach(fields($table) as $field => $args){ | |
if(ereg("^(.*)_id$", $field, $args)){ | |
$ret[] = array("table" => $args[1]."s", "source" => array($field), "target" => array("id")); | |
} | |
} | |
return $ret; | |
} | |
} | |
?> |
Added check for missed associations.
Missed links are blocks foreign tables on the scheme. Only links to present tables will be drawn
<?php
/** Convention foreign keys: plugin for Adminer
* Links for foreign keys by convention user_id => users.id. Useful for Ruby On Rails like standard schema conventions.
* @author Ivan Necas, @inecas
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
*/
class ConventionForeignKeys {
static $table_names;
function foreignKeys($table) {
$ret = array();
if(self::$table_names == NULL){
self::$table_names = array();
foreach(tables_list() as $tbl_syn => $tp) {
self::$table_names[] = str_replace("`","", $tbl_syn);
}
}
foreach(fields($table) as $field => $args){
if(ereg("^(.*)_id$", $field, $args) && in_array($args[1]."s", self::$table_names)){
$ret[] = array("table" => $args[1]."s", "source" => array($field), "target" => array("id"));
}
}
return $ret;
}
}
?>
Adminer 5 wrapped itself into a namespace and plugins now need to call Adminer's functions via this namespace.
Please update this Gist to this: https://gist.github.com/vrana/cadff264c067038600ba8a08917f24c3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ereg()
is deprecated as of PHP 5.3, this should be equivalent: