Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Ensure table in options not overriden
And don't try to set table at all if it's not possible to accurately
determine what table the user meant to use
  • Loading branch information
AD7six committed Feb 16, 2015
1 parent 0800e9e commit 697d76a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ORM/TableRegistry.php
Expand Up @@ -176,7 +176,7 @@ public static function get($alias, array $options = [])
if ($className) {
$options['className'] = $className;
} else {
if (!isset($options['table'])) {
if (!isset($options['table']) && strpos($options['className'], '\\') === false) {
list(, $table) = pluginSplit($options['className']);
$options['table'] = Inflector::underscore($table);
}
Expand Down
12 changes: 11 additions & 1 deletion tests/TestCase/ORM/TableRegistryTest.php
Expand Up @@ -184,8 +184,18 @@ public function testGetFallbacks()

$result = TableRegistry::get('R2D2', ['className' => 'Droids']);
$this->assertInstanceOf('Cake\ORM\Table', $result);
$this->assertEquals('droids', $result->table());
$this->assertEquals('droids', $result->table(), 'The table should be derived from the className');
$this->assertEquals('R2D2', $result->alias());

$result = TableRegistry::get('C3P0', ['className' => 'Droids', 'table' => 'rebels']);
$this->assertInstanceOf('Cake\ORM\Table', $result);
$this->assertEquals('rebels', $result->table(), 'The table should be taken from options');
$this->assertEquals('C3P0', $result->alias());

$result = TableRegistry::get('Stuff', ['className' => 'Cake\ORM\Table']);
$this->assertInstanceOf('Cake\ORM\Table', $result);
$this->assertEquals('stuff', $result->table(), 'The table should be drived from the alias');
$this->assertEquals('Stuff', $result->alias());
}

/**
Expand Down

0 comments on commit 697d76a

Please sign in to comment.