mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #3287 from dereuromark/2.5-bc-fix
Revert the removal of a BC relevant part.
This commit is contained in:
commit
c24304fc53
2 changed files with 57 additions and 12 deletions
|
@ -1638,7 +1638,7 @@ class DboSource extends DataSource {
|
|||
* Builds a string containing an SQL statement template.
|
||||
*
|
||||
* @param Model $Model Primary Model object.
|
||||
* @param Model $LinkModel Linked model object.
|
||||
* @param Model|null $LinkModel Linked model object.
|
||||
* @param string $type Association type, one of the model association types ie. hasMany.
|
||||
* @param string $association Association name.
|
||||
* @param array $assocData Association data.
|
||||
|
@ -1650,9 +1650,23 @@ class DboSource extends DataSource {
|
|||
*/
|
||||
public function generateAssociationQuery(Model $Model, $LinkModel, $type, $association, $assocData, &$queryData, $external) {
|
||||
$assocData = $this->_scrubQueryData($assocData);
|
||||
$queryData = $this->_scrubQueryData($queryData);
|
||||
|
||||
if ($LinkModel === null) {
|
||||
return '';
|
||||
return $this->buildStatement(
|
||||
array(
|
||||
'fields' => array_unique($queryData['fields']),
|
||||
'table' => $this->fullTableName($Model),
|
||||
'alias' => $Model->alias,
|
||||
'limit' => $queryData['limit'],
|
||||
'offset' => $queryData['offset'],
|
||||
'joins' => $queryData['joins'],
|
||||
'conditions' => $queryData['conditions'],
|
||||
'order' => $queryData['order'],
|
||||
'group' => $queryData['group']
|
||||
),
|
||||
$Model
|
||||
);
|
||||
}
|
||||
|
||||
if ($external && !empty($assocData['finderQuery'])) {
|
||||
|
@ -1699,8 +1713,6 @@ class DboSource extends DataSource {
|
|||
'conditions' => trim($this->conditions($conditions, true, false, $Model))
|
||||
);
|
||||
|
||||
$queryData = $this->_scrubQueryData($queryData);
|
||||
|
||||
$fields = array();
|
||||
if ($assocData['fields'] !== false) {
|
||||
$fields = $this->fields($LinkModel, $association, $assocData['fields']);
|
||||
|
|
|
@ -137,7 +137,6 @@ class DboSourceTest extends CakeTestCase {
|
|||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->__config = $this->db->config;
|
||||
|
||||
$this->testDb = new DboTestSource();
|
||||
$this->testDb->cacheSources = false;
|
||||
|
@ -869,7 +868,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
*/
|
||||
public function testQueryAssociationUnneededQueries() {
|
||||
$this->loadFixtures('Article', 'User', 'Comment', 'Attachment', 'Tag', 'ArticlesTag');
|
||||
$Comment = new Comment;
|
||||
$Comment = ClassRegistry::init('Comment');
|
||||
|
||||
$fullDebug = $this->db->fullDebug;
|
||||
$this->db->fullDebug = true;
|
||||
|
@ -917,6 +916,40 @@ class DboSourceTest extends CakeTestCase {
|
|||
$this->db->fullDebug = $fullDebug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that generation association queries without LinkModel still works.
|
||||
* Mainly BC.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGenerateAssociationQuery() {
|
||||
$this->loadFixtures('Article');
|
||||
$Article = ClassRegistry::init('Article');
|
||||
|
||||
$queryData = array(
|
||||
'conditions' => array(
|
||||
'Article.id' => 1
|
||||
),
|
||||
'fields' => array(
|
||||
'Article.id',
|
||||
'Article.title',
|
||||
),
|
||||
'joins' => array(),
|
||||
'limit' => 2,
|
||||
'offset' => 2,
|
||||
'order' => array('title'),
|
||||
'page' => 2,
|
||||
'group' => null,
|
||||
'callbacks' => 1
|
||||
);
|
||||
|
||||
$result = $this->db->generateAssociationQuery($Article, null, null, null, null, $queryData, false);
|
||||
$this->assertContains('SELECT', $result);
|
||||
$this->assertContains('FROM', $result);
|
||||
$this->assertContains('WHERE', $result);
|
||||
$this->assertContains('ORDER', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that fields() is using methodCache()
|
||||
*
|
||||
|
@ -1019,7 +1052,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
*/
|
||||
public function testTransactionLogging() {
|
||||
$conn = $this->getMock('MockPDO');
|
||||
$db = new DboTestSource;
|
||||
$db = new DboTestSource();
|
||||
$db->setConnection($conn);
|
||||
$conn->expects($this->exactly(2))->method('beginTransaction')
|
||||
->will($this->returnValue(true));
|
||||
|
@ -1132,7 +1165,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
$conn->expects($this->at(0))
|
||||
->method('quote')
|
||||
->will($this->returnValue('foo bar'));
|
||||
$db = new DboTestSource;
|
||||
$db = new DboTestSource();
|
||||
$db->setConnection($conn);
|
||||
$subQuery = $db->buildStatement(
|
||||
array(
|
||||
|
@ -1223,7 +1256,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testBuildJoinStatementWithTablePrefix($join, $expected) {
|
||||
$db = new DboTestSource;
|
||||
$db = new DboTestSource();
|
||||
$db->config['prefix'] = 'pre_';
|
||||
$result = $db->buildJoinStatement($join);
|
||||
$this->assertEquals($expected, $result);
|
||||
|
@ -1237,7 +1270,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
public function testConditionKeysToString() {
|
||||
$Article = ClassRegistry::init('Article');
|
||||
$conn = $this->getMock('MockPDO', array('quote'));
|
||||
$db = new DboTestSource;
|
||||
$db = new DboTestSource();
|
||||
$db->setConnection($conn);
|
||||
|
||||
$conn->expects($this->at(0))
|
||||
|
@ -1273,7 +1306,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
'extra' => 'something virtual'
|
||||
);
|
||||
$conn = $this->getMock('MockPDO', array('quote'));
|
||||
$db = new DboTestSource;
|
||||
$db = new DboTestSource();
|
||||
$db->setConnection($conn);
|
||||
|
||||
$conn->expects($this->at(0))
|
||||
|
@ -1304,7 +1337,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testLimit() {
|
||||
$db = new DboTestSource;
|
||||
$db = new DboTestSource();
|
||||
|
||||
$result = $db->limit('0');
|
||||
$this->assertNull($result);
|
||||
|
|
Loading…
Reference in a new issue