Skip to content

Instantly share code, notes, and snippets.

@vrana
Forked from iNecas/convention-foreign-keys.php
Last active March 16, 2025 06:37
Show Gist options
  • Save vrana/cadff264c067038600ba8a08917f24c3 to your computer and use it in GitHub Desktop.
Save vrana/cadff264c067038600ba8a08917f24c3 to your computer and use it in GitHub Desktop.
Convention foreign keys: plugin for Adminer (http://www.adminer.org)
<?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