diff --git a/cake/libs/class_registry.php b/cake/libs/class_registry.php index 3e2ced4b6..61d328dfb 100644 --- a/cake/libs/class_registry.php +++ b/cake/libs/class_registry.php @@ -235,16 +235,16 @@ class ClassRegistry { function &getObject($key) { $_this =& ClassRegistry::getInstance(); $key = Inflector::underscore($key); + $return = false; if (isset($_this->__objects[$key])) { - return $_this->__objects[$key]; + $return =& $_this->__objects[$key]; } else { $key = $_this->__getMap($key); if (isset($_this->__objects[$key])) { - return $_this->__objects[$key]; + $return =& $_this->__objects[$key]; } } - $return = false; return $return; } /* @@ -282,7 +282,7 @@ class ClassRegistry { $duplicate = false; if ($_this->isKeySet($alias)) { $model =& $_this->getObject($alias); - if ($model->name === $class) { + if (is_a($model, $class)) { $duplicate =& $model; } unset($model); diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index 67cd2b059..5a27b1d49 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -3511,29 +3511,29 @@ class DboSourceTest extends CakeTestCase { $Apple =& ClassRegistry::init('Apple'); $Article =& ClassRegistry::init('Article'); - $result = $this->testDb->rawQuery('SELECT color, name FROM ' . $this->testDb->fullTableName('apples')); + $result = $this->db->rawQuery('SELECT color, name FROM ' . $this->db->fullTableName('apples')); $this->assertTrue(!empty($result)); - $result = $this->testDb->fetchRow($result); - $expected = array($this->testDb->fullTableName('apples', false) => array( + $result = $this->db->fetchRow($result); + $expected = array($this->db->fullTableName('apples', false) => array( 'color' => 'Red 1', 'name' => 'Red Apple 1' )); $this->assertEqual($result, $expected); - $result = $this->testDb->fetchAll('SELECT name FROM ' . $this->testDb->fullTableName('apples') . ' ORDER BY id'); + $result = $this->db->fetchAll('SELECT name FROM ' . $this->testDb->fullTableName('apples') . ' ORDER BY id'); $expected = array( - array($this->testDb->fullTableName('apples', false) => array('name' => 'Red Apple 1')), - array($this->testDb->fullTableName('apples', false) => array('name' => 'Bright Red Apple')), - array($this->testDb->fullTableName('apples', false) => array('name' => 'green blue')), - array($this->testDb->fullTableName('apples', false) => array('name' => 'Test Name')), - array($this->testDb->fullTableName('apples', false) => array('name' => 'Blue Green')), - array($this->testDb->fullTableName('apples', false) => array('name' => 'My new apple')), - array($this->testDb->fullTableName('apples', false) => array('name' => 'Some odd color')) + array($this->db->fullTableName('apples', false) => array('name' => 'Red Apple 1')), + array($this->db->fullTableName('apples', false) => array('name' => 'Bright Red Apple')), + array($this->db->fullTableName('apples', false) => array('name' => 'green blue')), + array($this->db->fullTableName('apples', false) => array('name' => 'Test Name')), + array($this->db->fullTableName('apples', false) => array('name' => 'Blue Green')), + array($this->db->fullTableName('apples', false) => array('name' => 'My new apple')), + array($this->db->fullTableName('apples', false) => array('name' => 'Some odd color')) ); $this->assertEqual($result, $expected); - $result = $this->testDb->field($this->testDb->fullTableName('apples', false), 'SELECT color, name FROM ' . $this->testDb->fullTableName('apples') . ' ORDER BY id'); + $result = $this->db->field($this->testDb->fullTableName('apples', false), 'SELECT color, name FROM ' . $this->testDb->fullTableName('apples') . ' ORDER BY id'); $expected = array( 'color' => 'Red 1', 'name' => 'Red Apple 1' @@ -3541,7 +3541,7 @@ class DboSourceTest extends CakeTestCase { $this->assertEqual($result, $expected); $Apple->unbindModel(array(), false); - $result = $this->testDb->read($Apple, array( + $result = $this->db->read($Apple, array( 'fields' => array($Apple->escapeField('name')), 'conditions' => null, 'recursive' => -1 @@ -3557,11 +3557,12 @@ class DboSourceTest extends CakeTestCase { ); $this->assertEqual($result, $expected); - $result = $this->testDb->read($Article, array( + $result = $this->db->read($Article, array( 'fields' => array('id', 'user_id', 'title'), 'conditions' => null, 'recursive' => 1 )); + $this->assertTrue(Set::matches('/Article[id=1]', $result)); $this->assertTrue(Set::matches('/Comment[id=1]', $result)); $this->assertTrue(Set::matches('/Comment[id=2]', $result));