From 169b0a5c3f211e8ff8138514466b062acc7ff35e Mon Sep 17 00:00:00 2001 From: Graham Weldon Date: Wed, 1 Jun 2011 00:38:09 +0800 Subject: [PATCH] Consolidate table prefix removal. --- cake/libs/model/cake_schema.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cake/libs/model/cake_schema.php b/cake/libs/model/cake_schema.php index 1d845128bea..c92b9dd0cda 100644 --- a/cake/libs/model/cake_schema.php +++ b/cake/libs/model/cake_schema.php @@ -257,7 +257,7 @@ function read($options = array()) { if ($prefix && strpos($table, $prefix) !== 0) { continue; } - $table = preg_replace('/^' . preg_quote($prefix) . '/', '', $table); + $table = $this->_noPrefixTable($prefix, $table); if (in_array($fulltable, $currentTables)) { $key = array_search($fulltable, $currentTables); @@ -279,7 +279,7 @@ function read($options = array()) { } if (in_array($withTable, $currentTables)) { $key = array_search($withTable, $currentTables); - $noPrefixWith = str_replace($prefix, '', $withTable); + $noPrefixWith = $this->_noPrefixTable($prefix, $withTable); $tables[$noPrefixWith] = $this->__columns($Object->$class); $tables[$noPrefixWith]['indexes'] = $db->index($Object->$class); @@ -300,7 +300,7 @@ function read($options = array()) { if (strpos($table, $prefix) !== 0) { continue; } - $table = preg_replace('/^' . preg_quote($prefix) . '/', '', $table); + $table = $this->_noPrefixTable($prefix, $table); } $Object = new AppModel(array( 'name' => Inflector::classify($table), 'table' => $table, 'ds' => $connection @@ -695,4 +695,8 @@ function _compareIndexes($new, $old) { } return array_filter(compact('add', 'drop')); } + + function _noPrefixTable($prefix, $table) { + return preg_replace('/^' . preg_quote($prefix) . '/', '', $table); + } }