Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

setting defaults in the DBO so you do not need to pass every field po…

…ssible to avoid errors. also adds a test for calling with some missing fields. fixes #1779
  • Loading branch information...
commit 2ad0f8b8db3b08ae762e6f62bb38886a90c1c151 1 parent c754fb2
@dogmatic69 dogmatic69 authored
View
19 lib/Cake/Model/Datasource/DboSource.php
@@ -195,6 +195,23 @@ class DboSource extends DataSource {
);
/**
+ * Default fields that are used by the DBO
+ *
+ * @var array
+ */
+ protected $_queryDefaults = array(
+ 'conditions' => array(),
+ 'fields' => null,
+ 'table' => null,
+ 'alias' => null,
+ 'order' => null,
+ 'limit' => null,
+ 'joins' => array(),
+ 'group' => null,
+ 'offset' => null
+ );
+
+/**
* Separator string for virtualField composition
*
* @var string
@@ -1665,7 +1682,7 @@ public function buildJoinStatement($join) {
* @see DboSource::renderStatement()
*/
public function buildStatement($query, $model) {
- $query = array_merge(array('offset' => null, 'joins' => array()), $query);
+ $query = array_merge($this->_queryDefaults, $query);
if (!empty($query['joins'])) {
$count = count($query['joins']);
for ($i = 0; $i < $count; $i++) {
View
23 lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
@@ -843,4 +843,27 @@ public function testTransactionLogging() {
$log = $db->getLog();
$this->assertEquals($expected, $log['log'][0]);
}
+
+/**
+ * Test build statement with some fields missing
+ *
+ * @return void
+ */
+ public function testBuildStatementDefaults() {
+ $conn = $this->getMock('MockPDO');
+ $db = new DboTestSource;
+ $db->setConnection($conn);
+ $subQuery = $db->buildStatement(
+ array(
+ 'fields' => array('DISTINCT(AssetsTag.asset_id)'),
+ 'table' => "assets_tags",
+ 'alias'=>"AssetsTag",
+ 'conditions' => array("Tag.name"=>'foo bar'),
+ 'limit' => null,
+ 'group' => "AssetsTag.asset_id"
+ ),
+ $this->Model
+ );
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.