Beispiel #1
0
 /**
  * Returns a list of foreign keys that refer a table.
  */
 public function getReferencingKeys($table)
 {
     $meta = array();
     switch ($this->connection->getAttribute(PDO::ATTR_DRIVER_NAME)) {
         case 'mysql':
             foreach ($this->loadKeys() as $info) {
                 if ($info['referenced_table_name'] === $table) {
                     $meta[] = array('table' => $info['table_name'], 'column' => $info['column_name'], 'referenced_table' => $info['referenced_table_name'], 'referenced_column' => $info['referenced_column_name']);
                 }
             }
             return $meta;
         case 'pgsql':
         case 'sqlite':
             foreach ($this->getTables() as $tbl) {
                 if ($tbl != $table) {
                     foreach ($this->getForeignKeys($tbl) as $info) {
                         if ($info['referenced_table'] == $table) {
                             $meta[] = $info;
                         }
                     }
                 }
             }
             return $meta;
         default:
             throw new \RuntimeException("Meta not supported.");
     }
 }