-
-
Save vrana/cadff264c067038600ba8a08917f24c3 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(Adminer\fields($table) as $field => $args){ | |
if(ereg("^(.*)_id$", $field, $args)){ | |
$ret[] = array("table" => $args[1]."s", "source" => array($field), "target" => array("id")); | |
} | |
} | |
return $ret; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment