mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #2289 from bar/2.5-optimize-dbosource
First part of the DboSource cleanup.
This commit is contained in:
commit
df5fc2304a
3 changed files with 528 additions and 491 deletions
|
@ -183,12 +183,12 @@ class DataSource extends Object {
|
|||
*
|
||||
* To-be-overridden in subclasses.
|
||||
*
|
||||
* @param Model $model The Model to be created.
|
||||
* @param Model $Model The Model to be created.
|
||||
* @param array $fields An Array of fields to be saved.
|
||||
* @param array $values An Array of values to save.
|
||||
* @return boolean success
|
||||
*/
|
||||
public function create(Model $model, $fields = null, $values = null) {
|
||||
public function create(Model $Model, $fields = null, $values = null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -197,12 +197,12 @@ class DataSource extends Object {
|
|||
*
|
||||
* To-be-overridden in subclasses.
|
||||
*
|
||||
* @param Model $model The model being read.
|
||||
* @param Model $Model The model being read.
|
||||
* @param array $queryData An array of query data used to find the data you want
|
||||
* @param integer $recursive Number of levels of association
|
||||
* @return mixed
|
||||
*/
|
||||
public function read(Model $model, $queryData = array(), $recursive = null) {
|
||||
public function read(Model $Model, $queryData = array(), $recursive = null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -211,13 +211,13 @@ class DataSource extends Object {
|
|||
*
|
||||
* To-be-overridden in subclasses.
|
||||
*
|
||||
* @param Model $model Instance of the model class being updated
|
||||
* @param Model $Model Instance of the model class being updated
|
||||
* @param array $fields Array of fields to be updated
|
||||
* @param array $values Array of values to be update $fields to.
|
||||
* @param mixed $conditions
|
||||
* @return boolean Success
|
||||
*/
|
||||
public function update(Model $model, $fields = null, $values = null, $conditions = null) {
|
||||
public function update(Model $Model, $fields = null, $values = null, $conditions = null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -226,11 +226,11 @@ class DataSource extends Object {
|
|||
*
|
||||
* To-be-overridden in subclasses.
|
||||
*
|
||||
* @param Model $model The model class having record(s) deleted
|
||||
* @param Model $Model The model class having record(s) deleted
|
||||
* @param mixed $conditions The conditions to use for deleting.
|
||||
* @return boolean Success
|
||||
*/
|
||||
public function delete(Model $model, $conditions = null) {
|
||||
public function delete(Model $Model, $conditions = null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -319,94 +319,89 @@ class DataSource extends Object {
|
|||
* @param string $query Query string needing replacements done.
|
||||
* @param array $data Array of data with values that will be inserted in placeholders.
|
||||
* @param string $association Name of association model being replaced
|
||||
* @param array $assocData
|
||||
* @param Model $model Instance of the model to replace $__cakeID__$
|
||||
* @param Model $linkModel Instance of model to replace $__cakeForeignKey__$
|
||||
* @param Model $Model Model instance
|
||||
* @param array $stack
|
||||
* @return string String of query data with placeholders replaced.
|
||||
*/
|
||||
public function insertQueryData($query, $data, $association, $assocData, Model $model, Model $linkModel, $stack) {
|
||||
public function insertQueryData($query, $data, $association, Model $Model, $stack) {
|
||||
$keys = array('{$__cakeID__$}', '{$__cakeForeignKey__$}');
|
||||
|
||||
$modelAlias = $Model->alias;
|
||||
|
||||
foreach ($keys as $key) {
|
||||
$val = null;
|
||||
$type = null;
|
||||
|
||||
if (strpos($query, $key) !== false) {
|
||||
switch ($key) {
|
||||
case '{$__cakeID__$}':
|
||||
if (isset($data[$model->alias]) || isset($data[$association])) {
|
||||
if (isset($data[$model->alias][$model->primaryKey])) {
|
||||
$val = $data[$model->alias][$model->primaryKey];
|
||||
} elseif (isset($data[$association][$model->primaryKey])) {
|
||||
$val = $data[$association][$model->primaryKey];
|
||||
}
|
||||
} else {
|
||||
$found = false;
|
||||
foreach (array_reverse($stack) as $assoc) {
|
||||
if (isset($data[$assoc]) && isset($data[$assoc][$model->primaryKey])) {
|
||||
$val = $data[$assoc][$model->primaryKey];
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
$val = '';
|
||||
}
|
||||
}
|
||||
$type = $model->getColumnType($model->primaryKey);
|
||||
break;
|
||||
case '{$__cakeForeignKey__$}':
|
||||
foreach ($model->associations() as $name) {
|
||||
foreach ($model->$name as $assocName => $assoc) {
|
||||
if ($assocName === $association) {
|
||||
if (isset($assoc['foreignKey'])) {
|
||||
$foreignKey = $assoc['foreignKey'];
|
||||
$assocModel = $model->$assocName;
|
||||
$type = $assocModel->getColumnType($assocModel->primaryKey);
|
||||
|
||||
if (isset($data[$model->alias][$foreignKey])) {
|
||||
$val = $data[$model->alias][$foreignKey];
|
||||
} elseif (isset($data[$association][$foreignKey])) {
|
||||
$val = $data[$association][$foreignKey];
|
||||
} else {
|
||||
$found = false;
|
||||
foreach (array_reverse($stack) as $assoc) {
|
||||
if (isset($data[$assoc]) && isset($data[$assoc][$foreignKey])) {
|
||||
$val = $data[$assoc][$foreignKey];
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
$val = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
break 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (empty($val) && $val !== '0') {
|
||||
return false;
|
||||
}
|
||||
$query = str_replace($key, $this->value($val, $type), $query);
|
||||
if (strpos($query, $key) === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$insertKey = $InsertModel = null;
|
||||
switch ($key) {
|
||||
case '{$__cakeID__$}':
|
||||
$InsertModel = $Model;
|
||||
$insertKey = $Model->primaryKey;
|
||||
|
||||
break;
|
||||
case '{$__cakeForeignKey__$}':
|
||||
foreach ($Model->associations() as $type) {
|
||||
foreach ($Model->{$type} as $assoc => $assocData) {
|
||||
if ($assoc !== $association) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($assocData['foreignKey'])) {
|
||||
$InsertModel = $Model->{$assoc};
|
||||
$insertKey = $assocData['foreignKey'];
|
||||
}
|
||||
|
||||
break 3;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$val = $dataType = null;
|
||||
if (!empty($insertKey) && !empty($InsertModel)) {
|
||||
if (isset($data[$modelAlias][$insertKey])) {
|
||||
$val = $data[$modelAlias][$insertKey];
|
||||
} elseif (isset($data[$association][$insertKey])) {
|
||||
$val = $data[$association][$insertKey];
|
||||
} else {
|
||||
$found = false;
|
||||
foreach (array_reverse($stack) as $assocData) {
|
||||
if (isset($data[$assocData]) && isset($data[$assocData][$insertKey])) {
|
||||
$val = $data[$assocData][$insertKey];
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
$val = '';
|
||||
}
|
||||
}
|
||||
|
||||
$dataType = $InsertModel->getColumnType($InsertModel->primaryKey);
|
||||
}
|
||||
|
||||
if (empty($val) && $val !== '0') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = str_replace($key, $this->value($val, $dataType), $query);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* To-be-overridden in subclasses.
|
||||
*
|
||||
* @param Model $model Model instance
|
||||
* @param Model $Model Model instance
|
||||
* @param string $key Key name to make
|
||||
* @return string Key name for model.
|
||||
*/
|
||||
public function resolveKey(Model $model, $key) {
|
||||
return $model->alias . $key;
|
||||
public function resolveKey(Model $Model, $key) {
|
||||
return $Model->alias . $key;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1142,18 +1142,18 @@ class MysqlTest extends CakeTestCase {
|
|||
$external = isset($assocData['external']);
|
||||
|
||||
if ($this->Model->Category2->alias == $linkModel->alias && $type !== 'hasAndBelongsToMany' && $type !== 'hasMany') {
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external);
|
||||
$this->assertFalse(empty($result));
|
||||
} else {
|
||||
if ($this->Model->Category2->useDbConfig == $linkModel->useDbConfig) {
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model->Category2, $linkModel, $type, $assoc, $assocData, $queryData, $external);
|
||||
$this->assertFalse(empty($result));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$query = $this->Dbo->generateAssociationQuery($this->Model->Category2, $null, null, null, null, $queryData, false, $null);
|
||||
$query = $this->Dbo->buildAssociationQuery($this->Model->Category2, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+(.+)FROM(.+)`Category2`\.`group_id`\s+=\s+`Group`\.`id`\)\s+LEFT JOIN(.+)WHERE\s+1 = 1\s*$/', $query);
|
||||
|
||||
$this->Model = new TestModel4();
|
||||
|
@ -1162,13 +1162,11 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'belongsTo', 'model' => 'TestModel4Parent');
|
||||
$queryData = array();
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$_queryData = $queryData;
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$expected = array(
|
||||
|
@ -1200,7 +1198,7 @@ class MysqlTest extends CakeTestCase {
|
|||
$queryData['joins'][0]['table'] = $this->Dbo->fullTableName($queryData['joins'][0]['table']);
|
||||
$this->assertEquals($expected, $queryData);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel4Parent`\.`id`, `TestModel4Parent`\.`name`, `TestModel4Parent`\.`created`, `TestModel4Parent`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/FROM\s+\S+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+\S+`test_model4` AS `TestModel4Parent`/', $result);
|
||||
$this->assertRegExp('/\s+ON\s+\(`TestModel4`.`parent_id` = `TestModel4Parent`.`id`\)\s+WHERE/', $result);
|
||||
|
@ -1208,7 +1206,7 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$params['assocData']['type'] = 'INNER';
|
||||
$this->Model->belongsTo['TestModel4Parent']['type'] = 'INNER';
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $_queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $_queryData, $params['external']);
|
||||
$this->assertTrue($result);
|
||||
$this->assertEquals('INNER', $_queryData['joins'][0]['type']);
|
||||
}
|
||||
|
@ -1315,14 +1313,12 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'hasOne', 'model' => 'TestModel9');
|
||||
$queryData = array();
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel8`\.`id`, `TestModel8`\.`test_model9_id`, `TestModel8`\.`name`, `TestModel8`\.`created`, `TestModel8`\.`updated`, `TestModel9`\.`id`, `TestModel9`\.`test_model8_id`, `TestModel9`\.`name`, `TestModel9`\.`created`, `TestModel9`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/FROM\s+\S+`test_model8` AS `TestModel8`\s+LEFT JOIN\s+\S+`test_model9` AS `TestModel9`/', $result);
|
||||
$this->assertRegExp('/\s+ON\s+\(`TestModel9`\.`name` != \'mariano\'\s+AND\s+`TestModel9`.`test_model8_id` = `TestModel8`.`id`\)\s+WHERE/', $result);
|
||||
|
@ -1341,14 +1337,12 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'belongsTo', 'model' => 'TestModel8');
|
||||
$queryData = array();
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel9`\.`id`, `TestModel9`\.`test_model8_id`, `TestModel9`\.`name`, `TestModel9`\.`created`, `TestModel9`\.`updated`, `TestModel8`\.`id`, `TestModel8`\.`test_model9_id`, `TestModel8`\.`name`, `TestModel8`\.`created`, `TestModel8`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/FROM\s+\S+`test_model9` AS `TestModel9`\s+LEFT JOIN\s+\S+`test_model8` AS `TestModel8`/', $result);
|
||||
$this->assertRegExp('/\s+ON\s+\(`TestModel8`\.`name` != \'larry\'\s+AND\s+`TestModel9`.`test_model8_id` = `TestModel8`.`id`\)\s+WHERE/', $result);
|
||||
|
@ -1367,15 +1361,13 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'belongsTo', 'model' => 'TestModel4Parent');
|
||||
$queryData = array('conditions' => array('TestModel4Parent.name !=' => 'mariano'));
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel4Parent`\.`id`, `TestModel4Parent`\.`name`, `TestModel4Parent`\.`created`, `TestModel4Parent`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/FROM\s+\S+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+\S+`test_model4` AS `TestModel4Parent`/', $result);
|
||||
$this->assertRegExp('/\s+ON\s+\(`TestModel4`.`parent_id` = `TestModel4Parent`.`id`\)\s+WHERE/', $result);
|
||||
|
@ -1397,14 +1389,12 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'belongsTo', 'model' => 'ArticleFeatured2');
|
||||
$queryData = array('conditions' => array());
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Featured2, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Featured2, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Featured2, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertTrue($result);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Featured2, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Featured2, $queryData);
|
||||
|
||||
$this->assertRegExp(
|
||||
'/^SELECT\s+`Featured2`\.`id`, `Featured2`\.`article_id`, `Featured2`\.`category_id`, `Featured2`\.`name`,\s+' .
|
||||
|
@ -1429,12 +1419,10 @@ class MysqlTest extends CakeTestCase {
|
|||
$binding = array('type' => 'hasOne', 'model' => 'TestModel5');
|
||||
|
||||
$queryData = array();
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$testModel5Table = $this->Dbo->fullTableName($this->Model->TestModel5);
|
||||
|
@ -1442,7 +1430,7 @@ class MysqlTest extends CakeTestCase {
|
|||
$expected = ' LEFT JOIN ' . $testModel5Table . ' AS `TestModel5` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)';
|
||||
$this->assertEquals(trim($expected), trim($result));
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+/', $result);
|
||||
$this->assertRegExp('/`test_model5` AS `TestModel5`\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE/', $result);
|
||||
|
@ -1462,15 +1450,13 @@ class MysqlTest extends CakeTestCase {
|
|||
$binding = array('type' => 'hasOne', 'model' => 'TestModel5');
|
||||
|
||||
$queryData = array('conditions' => array('TestModel5.name !=' => 'mariano'));
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+\S+`test_model5` AS `TestModel5`/', $result);
|
||||
|
@ -1490,12 +1476,10 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'belongsTo', 'model' => 'TestModel4');
|
||||
$queryData = array();
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$testModel4Table = $this->Dbo->fullTableName($this->Model->TestModel4, true, true);
|
||||
|
@ -1503,7 +1487,7 @@ class MysqlTest extends CakeTestCase {
|
|||
$expected = ' LEFT JOIN ' . $testModel4Table . ' AS `TestModel4` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)';
|
||||
$this->assertEquals(trim($expected), trim($result));
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`, `TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model5` AS `TestModel5`\s+LEFT JOIN\s+\S+`test_model4` AS `TestModel4`/', $result);
|
||||
$this->assertRegExp('/\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE\s+/', $result);
|
||||
|
@ -1522,12 +1506,10 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'belongsTo', 'model' => 'TestModel4');
|
||||
$queryData = array('conditions' => array('TestModel5.name !=' => 'mariano'));
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertTrue($result);
|
||||
|
||||
$testModel4Table = $this->Dbo->fullTableName($this->Model->TestModel4, true, true);
|
||||
|
@ -1535,7 +1517,7 @@ class MysqlTest extends CakeTestCase {
|
|||
$expected = ' LEFT JOIN ' . $testModel4Table . ' AS `TestModel4` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)';
|
||||
$this->assertEquals(trim($expected), trim($result));
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`, `TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model5` AS `TestModel5`\s+LEFT JOIN\s+\S+`test_model4` AS `TestModel4`/', $result);
|
||||
$this->assertRegExp('/\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE\s+/', $result);
|
||||
|
@ -1554,18 +1536,16 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
|
||||
$queryData = array();
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model6` AS `TestModel6`\s+WHERE/', $result);
|
||||
$this->assertRegExp('/\s+WHERE\s+`TestModel6`.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)/', $result);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/\s+WHERE\s+(?:\()?\s*1 = 1\s*(?:\))?\s*$/', $result);
|
||||
|
@ -1585,12 +1565,10 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
|
||||
$queryData = array();
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertRegExp(
|
||||
'/^SELECT\s+' .
|
||||
'`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+' .
|
||||
|
@ -1600,7 +1578,7 @@ class MysqlTest extends CakeTestCase {
|
|||
'\s*$/', $result
|
||||
);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp(
|
||||
'/^SELECT\s+' .
|
||||
'`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+' .
|
||||
|
@ -1622,17 +1600,15 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
|
||||
$queryData = array('conditions' => array('TestModel5.name !=' => 'mariano'));
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/\s+WHERE\s+(?:\()?`TestModel5`.`name`\s+!=\s+\'mariano\'(?:\))?\s*$/', $result);
|
||||
|
@ -1655,19 +1631,17 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
|
||||
$queryData = array();
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
|
||||
$this->assertRegExp('/\s+LIMIT 2,\s*5\s*$/', $result);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
|
||||
|
@ -1691,19 +1665,16 @@ class MysqlTest extends CakeTestCase {
|
|||
$this->Model->hasMany['TestModel6']['limit'] = 5;
|
||||
|
||||
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
|
||||
$queryData = array();
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
|
||||
$this->assertRegExp('/\s+LIMIT 5,\s*5\s*$/', $result);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
|
||||
|
@ -1723,51 +1694,45 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
|
||||
$queryData = array('fields' => array('`TestModel5`.`name`'));
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel5`\.`name`, `TestModel5`\.`id`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
|
||||
|
||||
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
|
||||
$queryData = array('fields' => array('`TestModel5`.`id`, `TestModel5`.`name`'));
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`name`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
|
||||
|
||||
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
|
||||
$queryData = array('fields' => array('`TestModel5`.`name`', '`TestModel5`.`created`'));
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`id`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
|
||||
|
@ -1776,17 +1741,15 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
|
||||
$queryData = array('fields' => array('`TestModel5`.`id`', '`TestModel5`.`name`'));
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel6`\.`name`, `TestModel6`\.`test_model5_id`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`name`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
|
||||
|
@ -1797,17 +1760,15 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
|
||||
$queryData = array('fields' => array('`TestModel5`.`id`', '`TestModel5`.`name`'));
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`name`, `TestModel6`\.`test_model5_id`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`name`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
|
||||
|
@ -1818,17 +1779,15 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
|
||||
$queryData = array('fields' => array('`TestModel5`.`id`', '`TestModel5`.`name`'));
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel6`\.`test_model5_id`, `TestModel6`\.`name`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`name`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
|
||||
|
@ -1848,13 +1807,10 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
|
||||
$queryData = array('fields' => array('MIN(`TestModel5`.`test_model4_id`)'));
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
$this->Model->recursive = 0;
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, $params['type'], $params['assoc'], $params['assocData'], $queryData, false, $resultSet);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+MIN\(`TestModel5`\.`test_model4_id`\)\s+FROM/', $result);
|
||||
}
|
||||
|
||||
|
@ -1870,12 +1826,10 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'hasAndBelongsToMany', 'model' => 'TestModel7');
|
||||
$queryData = array();
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = $this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$assocTable = $this->Dbo->fullTableName($this->Model->TestModel4TestModel7, true, true);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model7` AS `TestModel7`\s+JOIN\s+' . $assocTable . '/', $result);
|
||||
|
@ -1883,7 +1837,7 @@ class MysqlTest extends CakeTestCase {
|
|||
$this->assertRegExp('/\s+AND\s+`TestModel4TestModel7`\.`test_model7_id`\s+=\s+`TestModel7`\.`id`\)/', $result);
|
||||
$this->assertRegExp('/WHERE\s+(?:\()?1 = 1(?:\))?\s*$/', $result);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model4` AS `TestModel4`\s+WHERE/', $result);
|
||||
$this->assertRegExp('/\s+WHERE\s+(?:\()?1 = 1(?:\))?\s*$/', $result);
|
||||
|
@ -1901,18 +1855,16 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'hasAndBelongsToMany', 'model' => 'TestModel7');
|
||||
$queryData = array('conditions' => array('TestModel4.name !=' => 'mariano'));
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = $this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model7`\s+AS\s+`TestModel7`\s+JOIN\s+\S+`test_model4_test_model7`\s+AS\s+`TestModel4TestModel7`/', $result);
|
||||
$this->assertRegExp('/\s+ON\s+\(`TestModel4TestModel7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}/', $result);
|
||||
$this->assertRegExp('/\s+AND\s+`TestModel4TestModel7`\.`test_model7_id`\s+=\s+`TestModel7`\.`id`\)\s+WHERE\s+/', $result);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model4` AS `TestModel4`\s+WHERE\s+(?:\()?`TestModel4`.`name`\s+!=\s+\'mariano\'(?:\))?\s*$/', $result);
|
||||
}
|
||||
|
@ -1934,19 +1886,17 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'hasAndBelongsToMany', 'model' => 'TestModel7');
|
||||
$queryData = array();
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model7`\s+AS\s+`TestModel7`\s+JOIN\s+\S+`test_model4_test_model7`\s+AS\s+`TestModel4TestModel7`/', $result);
|
||||
$this->assertRegExp('/\s+ON\s+\(`TestModel4TestModel7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}\s+/', $result);
|
||||
$this->assertRegExp('/\s+AND\s+`TestModel4TestModel7`\.`test_model7_id`\s+=\s+`TestModel7`\.`id`\)\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/\s+(?:\()?1\s+=\s+1(?:\))?\s*\s+LIMIT 2,\s*5\s*$/', $result);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model4` AS `TestModel4`\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
|
||||
|
||||
|
@ -1970,19 +1920,17 @@ class MysqlTest extends CakeTestCase {
|
|||
|
||||
$binding = array('type' => 'hasAndBelongsToMany', 'model' => 'TestModel7');
|
||||
$queryData = array();
|
||||
$resultSet = null;
|
||||
$null = null;
|
||||
|
||||
$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external']);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model7`\s+AS\s+`TestModel7`\s+JOIN\s+\S+`test_model4_test_model7`\s+AS\s+`TestModel4TestModel7`/', $result);
|
||||
$this->assertRegExp('/\s+ON\s+\(`TestModel4TestModel7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}/', $result);
|
||||
$this->assertRegExp('/\s+AND\s+`TestModel4TestModel7`\.`test_model7_id`\s+=\s+`TestModel7`\.`id`\)\s+WHERE\s+/', $result);
|
||||
$this->assertRegExp('/\s+(?:\()?1\s+=\s+1(?:\))?\s*\s+LIMIT 5,\s*5\s*$/', $result);
|
||||
|
||||
$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
|
||||
$result = $this->Dbo->buildAssociationQuery($this->Model, $queryData);
|
||||
$this->assertRegExp('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result);
|
||||
$this->assertRegExp('/\s+FROM\s+\S+`test_model4` AS `TestModel4`\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
|
||||
|
||||
|
@ -2031,8 +1979,9 @@ class MysqlTest extends CakeTestCase {
|
|||
$expected = " WHERE SUM(`Post`.`comments_count`) > 500";
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $this->Dbo->conditions("(Post.created < '" . date('Y-m-d H:i') . "') GROUP BY YEAR(Post.created), MONTH(Post.created)");
|
||||
$expected = " WHERE (`Post`.`created` < '" . date('Y-m-d H:i') . "') GROUP BY YEAR(`Post`.`created`), MONTH(`Post`.`created`)";
|
||||
$date = date('Y-m-d H:i');
|
||||
$result = $this->Dbo->conditions("(Post.created < '" . $date . "') GROUP BY YEAR(Post.created), MONTH(Post.created)");
|
||||
$expected = " WHERE (`Post`.`created` < '" . $date . "') GROUP BY YEAR(`Post`.`created`), MONTH(`Post`.`created`)";
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $this->Dbo->conditions("score BETWEEN 90.1 AND 95.7");
|
||||
|
@ -2047,8 +1996,9 @@ class MysqlTest extends CakeTestCase {
|
|||
$expected = " WHERE `Aro`.`rght` = `Aro`.`lft` + 1.1";
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $this->Dbo->conditions("(Post.created < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(Post.created), MONTH(Post.created)");
|
||||
$expected = " WHERE (`Post`.`created` < '" . date('Y-m-d H:i:s') . "') GROUP BY YEAR(`Post`.`created`), MONTH(`Post`.`created`)";
|
||||
$date = date('Y-m-d H:i:s');
|
||||
$result = $this->Dbo->conditions("(Post.created < '" . $date . "') GROUP BY YEAR(Post.created), MONTH(Post.created)");
|
||||
$expected = " WHERE (`Post`.`created` < '" . $date . "') GROUP BY YEAR(`Post`.`created`), MONTH(`Post`.`created`)";
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = $this->Dbo->conditions('Sportstaette.sportstaette LIKE "%ru%" AND Sportstaette.sportstaettenart_id = 2');
|
||||
|
|
Loading…
Reference in a new issue