Skip to content

Commit

Permalink
fixes #6427, default datasource not loaded when ds is specified
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8197 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
gwoo committed Jun 16, 2009
1 parent a903a45 commit 88e0cfa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cake/libs/model/model.php
Expand Up @@ -372,6 +372,10 @@ function __construct($id = false, $table = null, $ds = null) {
} elseif ($table) {
$this->useTable = $table;
}

if ($ds !== null) {
$this->useDbConfig = $ds;
}

if (is_subclass_of($this, 'AppModel')) {
$appVars = get_class_vars('AppModel');
Expand Down
27 changes: 22 additions & 5 deletions cake/tests/cases/libs/model/model.test.php
Expand Up @@ -268,6 +268,23 @@ function testConstruct() {
$this->assertEqual($TestModel->actsAs, $expected);
$this->assertTrue(isset($TestModel->Behaviors->Containable));
}
/**
* test Model::__construct
*
* ensure that $actsAS and $_findMethods are merged.
*
* @return void
**/
function testConstructWithAlternateDataSource() {
$TestModel =& ClassRegistry::init(array(
'class' => 'DoesntMatter', 'ds' => 'test_suite', 'table' => false
));
$this->assertEqual('test_suite', $TestModel->useDbConfig);

//deprecated but test it anyway
$NewVoid =& new TheVoid(null, false, 'other');
$this->assertEqual('other', $NewVoid->useDbConfig);
}
/**
* testColumnTypeFetching method
*
Expand Down Expand Up @@ -3655,7 +3672,7 @@ function testFindCountDistinct() {
$TestModel->create(array('name' => 'project')) && $TestModel->save();
$TestModel->create(array('name' => 'project')) && $TestModel->save();
$TestModel->create(array('name' => 'project')) && $TestModel->save();

$result = $TestModel->find('count', array('fields' => 'DISTINCT name'));
$this->assertEqual($result, 4);
}
Expand Down Expand Up @@ -12539,8 +12556,8 @@ function testGroupBy() {
$this->assertEqual($result, $expected);

$rows = $Thread->find('all', array(
'group' => 'Thread.project_id',
'fields' => array('Thread.project_id', 'COUNT(*) AS total'),
'group' => 'Thread.project_id',
'fields' => array('Thread.project_id', 'COUNT(*) AS total'),
'order'=> 'Thread.project_id'
));
$result = array();
Expand Down Expand Up @@ -12617,14 +12634,14 @@ function testGroupBy() {
array('Product' => array('type' => 'Toy'), array('price' => 3))
);
$result = $Product->find('all',array(
'fields'=>array('Product.type','MIN(Product.price) as price'),
'fields'=>array('Product.type','MIN(Product.price) as price'),
'group'=> 'Product.type',
'order' => 'Product.type ASC'
));
$this->assertEqual($result, $expected);

$result = $Product->find('all', array(
'fields'=>array('Product.type','MIN(Product.price) as price'),
'fields'=>array('Product.type','MIN(Product.price) as price'),
'group'=> array('Product.type'),
'order' => 'Product.type ASC'));
$this->assertEqual($result, $expected);
Expand Down

0 comments on commit 88e0cfa

Please sign in to comment.