Browse Source

Enable CakePHP ORM to accept PostgreSQL and SQL Server schema.

MichalWadowski 11 years ago
parent
commit
bd0daa5dca
2 changed files with 10 additions and 2 deletions
  1. 10 1
      src/Database/Schema/Collection.php
  2. 0 1
      src/Database/Schema/PostgresSchema.php

+ 10 - 1
src/Database/Schema/Collection.php

@@ -107,8 +107,17 @@ class Collection {
 				return $cached;
 			}
 		}
-		$table = new Table($name);
 		$config = $this->_connection->config();
+		if (strpos($name, '.')) {
+			list($config['schema'], $name) = explode('.', $name);
+		}
+
+		list($sql, $params) = $this->_dialect->describeTableSql($name, $config);
+		$statement = $this->_executeSql($sql, $params);
+		if (count($statement) === 0) {
+			throw new Exception(sprintf('Cannot describe %s. It has 0 columns.', $name));
+		}
+		$table = new Table($name);
 
 		$this->_reflect('Column', $name, $config, $table);
 		if (count($table->columns()) === 0) {

+ 0 - 1
src/Database/Schema/PostgresSchema.php

@@ -163,7 +163,6 @@ class PostgresSchema extends BaseSchema {
 			FROM pg_catalog.pg_class c
 			LEFT JOIN pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace
 			WHERE c.relname = ?
-				AND pg_catalog.pg_table_is_visible(c.oid)
 				AND n.nspname = ?
 		)
 		AND c.oid = i.indrelid