From 88e0cfa2f856a004d7ccb4a12d2bf4a5f5282f8f Mon Sep 17 00:00:00 2001 From: gwoo Date: Tue, 16 Jun 2009 21:35:21 +0000 Subject: [PATCH] fixes #6427, default datasource not loaded when ds is specified git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8197 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/model.php | 4 ++++ cake/tests/cases/libs/model/model.test.php | 27 ++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index ae19e51ef..c18d035e0 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -372,6 +372,10 @@ class Model extends Overloadable { } elseif ($table) { $this->useTable = $table; } + + if ($ds !== null) { + $this->useDbConfig = $ds; + } if (is_subclass_of($this, 'AppModel')) { $appVars = get_class_vars('AppModel'); diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 240b27fce..a4b75847b 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -268,6 +268,23 @@ class ModelTest extends CakeTestCase { $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 * @@ -3655,7 +3672,7 @@ class ModelTest extends CakeTestCase { $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); } @@ -12539,8 +12556,8 @@ class ModelTest extends CakeTestCase { $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(); @@ -12617,14 +12634,14 @@ class ModelTest extends CakeTestCase { 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);