| | 51 | * lists table relations |
| | 52 | * |
| | 53 | * Expects an array of this format to be returned with all the relationships in it where the key is |
| | 54 | * the name of the foreign table, and the value is an array containing the local and foreign column |
| | 55 | * name |
| | 56 | * |
| | 57 | * Array |
| | 58 | * ( |
| | 59 | * [groups] => Array |
| | 60 | * ( |
| | 61 | * [local] => group_id |
| | 62 | * [foreign] => id |
| | 63 | * ) |
| | 64 | * ) |
| | 65 | * |
| | 66 | * @param string $table database table name |
| | 67 | * @return array |
| | 68 | */ |
| | 69 | public function listTableRelations($tableName) |
| | 70 | { |
| | 71 | $relations = array(); |
| | 72 | $sql = 'SELECT o1.name as table_name, c1.name as column_name, o2.name as referenced_table_name, c2.name as referenced_column_name, s.name as constraint_name FROM sysforeignkeys fk inner join sysobjects o1 on fk.fkeyid = o1.id inner join sysobjects o2 on fk.rkeyid = o2.id inner join syscolumns c1 on c1.id = o1.id and c1.colid = fk.fkey inner join syscolumns c2 on c2.id = o2.id and c2.colid = fk.rkey inner join sysobjects s on fk.constid = s.id AND o1.name = \'' . $tableName . '\''; |
| | 73 | $results = $this->conn->fetchAssoc($sql); |
| | 74 | foreach ($results as $result) |
| | 75 | { |
| | 76 | $result = array_change_key_case($result, CASE_LOWER); |
| | 77 | $relations[] = array('table' => $result['referenced_table_name'], |
| | 78 | 'local' => $result['column_name'], |
| | 79 | 'foreign' => $result['referenced_column_name']); |
| | 80 | } |
| | 81 | return $relations; |
| | 82 | } |
| | 83 | |
| | 84 | /** |