Changeset 1647
- Timestamp:
- 02/26/10 17:29:09 (5 months ago)
- Location:
- trunk
- Files:
-
- 2 modified
-
plugins/ullCorePlugin/lib/generator/ullQuery.class.php (modified) (11 diffs)
-
test/unit/ullCorePlugin/ullQueryTest.php (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/ullCorePlugin/lib/generator/ullQuery.class.php
r1611 r1647 5 5 * It allows giving related columns in the ull-relation syntax relative to a given base model. 6 6 * 7 * Example for ullVentoryItem: 'UllUser->username' selects the username of an item's owner7 * Example for the base class ullVentoryItem: 'UllUser->username' selects the username of an item's owner 8 8 * 9 9 * It automatically adds the necessary "from" clauses (=joins) and it administrates … … 37 37 $this->q = new ullDoctrineQuery(); 38 38 39 $from = $this->baseModel . ' x'; 40 $from .= ($indexBy) ? (' INDEXBY ' . $indexBy) : ''; 41 $this->q->from($from); 42 39 $doctrineFromString = $this->baseModel . ' x'; 40 $doctrineFromString .= ($indexBy) ? (' INDEXBY ' . $indexBy) : ''; 41 $this->q->from($doctrineFromString); 42 43 // add discriminator column for base model 43 44 $inheritanceKeyFields = $this->getInheritanceKeyField($this->baseModel); 44 45 if ($inheritanceKeyFields != null) … … 46 47 $this->addSelect($inheritanceKeyFields); 47 48 } 48 } 49 50 /** 51 * Inspect the inheritance map of a model and 52 * retrieve keyFields, if any. 53 * @param unknown_type $modelName 54 * @return array keyFields, if there are none, null 55 */ 56 private function getInheritanceKeyField($modelName) 57 { 58 $inheritanceMap = Doctrine::getTable($modelName)->getOption('inheritanceMap'); 59 $inheritanceFieldKeys = array_keys($inheritanceMap); 60 if (count($inheritanceFieldKeys) > 0) 61 { 62 return $inheritanceFieldKeys; 63 } 64 else 65 { 66 return null; 67 } 68 } 49 50 // add indexby column 51 if ($indexBy) 52 { 53 $this->addSelect($indexBy); 54 } 55 } 56 69 57 70 58 /****************************************** … … 72 60 ******************************************/ 73 61 74 75 62 /** 76 63 * Add SELECT columns … … 130 117 { 131 118 $this->handleWhere($where, $params, true); 132 133 return $this;134 }135 136 /**137 * Internal function which handles adding where clauses to138 * the query; supports AND and OR.139 *140 * @param $where the where term to add141 * @param $params142 * @param $coordinatorIsOr true if OR, false if AND143 * @return self144 */145 protected function handleWhere($where, $params = array(), $coordinatorIsOr)146 {147 preg_match('/^([a-z>_-])+/i', $where, $matches);148 $search = $matches[0];149 $replace = $this->relationStringToDoctrineQueryColumn($search);150 151 $where = str_replace($search, $replace, $where);152 153 if ($coordinatorIsOr)154 {155 $this->q->orWhere($where, $params);156 }157 else158 {159 $this->q->addWhere($where, $params);160 }161 162 $this->addRelationsToQuery();163 119 164 120 return $this; … … 287 243 } 288 244 245 /** 246 * SQL limit funtion 247 * 248 * @param int $limit 249 * @return self 250 */ 251 public function limit($limit) 252 { 253 $this->q->limit($limit); 254 255 return $this; 256 } 257 289 258 290 259 /** … … 319 288 return $this->q->count($params); 320 289 } 321 322 //TODO: add a indexBy($column) method.323 //@see http://www.doctrine-project.org/documentation/manual/1_2/pl/dql-doctrine-query-language:indexby-keyword324 //It should work this way:325 // In ullQuery we have no addFrom, since this is handled automatically326 // $q->indexBy('slug')327 //328 329 290 330 291 … … 391 352 * Also registeres the necessary relations 392 353 * 393 * Example for TestTable: 'UllUser->username'354 * Example for base model TestTable: 'UllUser->username' 394 355 * Returns 'x.ulluser.username' and adds the relation to UllUser 395 356 * … … 482 443 483 444 /** 484 * Add the internally collected relations to the query 485 * 486 * @param string $alias 487 * @param array $relations 445 * Adds the internally collected relations to the query 446 * 447 * @param string $alias Doctrine base alias 448 * @param array $relations Tree of relations relative to the base model 449 * Example: 450 * 451 * array(2) { 452 * ["UllLocation"]=> 453 * array(1) { 454 * ["Translation"]=> 455 * array(0) { 456 * } 457 * } 458 * ["UllJobTitle"]=> 459 * array(0) { 460 * } 461 *} 462 * @param $baseModel Class name of the base model 463 * 488 464 * @return none 489 465 */ 490 public function addRelationsToQuery($alias = 'x', $relations = array(), $fromModel = null)491 { 492 if ( !count($relations))466 public function addRelationsToQuery($alias = 'x', $relations = null, $baseModel = null) 467 { 468 if ($relations === null) 493 469 { 494 470 $relations = $this->relations; 495 471 } 496 472 497 if (!$fromModel) 498 { 499 $fromModel = $this->getBaseModel(); 500 } 501 473 if (!is_array($relations)) 474 { 475 throw new InvalidArgumentException('parameter "relations" must be an array'); 476 } 477 478 if (!$baseModel) 479 { 480 $baseModel = $this->getBaseModel(); 481 } 482 502 483 foreach ($relations as $relation => $subRelations) 503 484 { 504 485 $newAlias = $alias . '_' . $this->relationStringToAlias($relation, false); 505 486 506 $ from= $alias . '.' . $relation . ' ' . $newAlias;487 $doctrineFromString = $alias . '.' . $relation . ' ' . $newAlias; 507 488 508 489 $fromParts = $this->q->getDqlPart('from'); 509 490 510 $doctrineRelation = Doctrine::getTable($ fromModel)->getRelation($relation);511 512 if (!in_array($ from, $fromParts))491 $doctrineRelation = Doctrine::getTable($baseModel)->getRelation($relation); 492 493 if (!in_array($doctrineFromString, $fromParts)) 513 494 { 514 $this->q->addFrom($from); 515 495 $this->q->addFrom($doctrineFromString); 496 497 // add discriminator column 516 498 $inheritanceKeyFields = $this->getInheritanceKeyField($doctrineRelation->getClass()); 517 499 … … 524 506 } 525 507 508 // Hardcoded workaround for UllUser because we can't detect the discriminator column for the parent entity 526 509 if ($doctrineRelation->getClass() == 'UllEntity') 527 510 { … … 530 513 } 531 514 532 // This is necessary for Doctrine joins: 533 $selectId = $alias . '.' . $doctrineRelation->getLocalColumnName(); 534 $selectParts = $this->q->getDqlPart('select'); 535 if (!in_array($selectId, $selectParts)) 536 { 537 $this->q->addSelect($selectId); 538 } 539 515 // Select the local identifiers. This is necessary for Doctrine joins: 516 $identifiers = Doctrine::getTable($baseModel)->getIdentifier(); 517 518 if (!is_array($identifiers)) 519 { 520 $identifiers = array($identifiers); 521 } 522 523 foreach ($identifiers as $identifier) 524 { 525 $selectId = $alias . '.' . $identifier; 526 527 $selectParts = $this->q->getDqlPart('select'); 528 if (!in_array($selectId, $selectParts)) 529 { 530 $this->q->addSelect($selectId); 531 } 532 } 533 534 // Call the method recursivly for subrelations 540 535 if (count($subRelations)) 541 536 { 542 $doctrineRelation = Doctrine::getTable($fromModel)->getRelation($relation);543 544 537 $this->addRelationsToQuery($newAlias, $subRelations, $doctrineRelation->getClass()); 545 538 } 546 539 } 547 540 } 541 542 543 /** 544 * Inspect the inheritance map of a model and 545 * retrieve keyFields, if any. 546 * 547 * @param unknown_type $modelName 548 * @return array keyFields, if there are none, null 549 */ 550 protected function getInheritanceKeyField($modelName) 551 { 552 $inheritanceMap = Doctrine::getTable($modelName)->getOption('inheritanceMap'); 553 $inheritanceFieldKeys = array_keys($inheritanceMap); 554 if (count($inheritanceFieldKeys) > 0) 555 { 556 return $inheritanceFieldKeys; 557 } 558 else 559 { 560 return null; 561 } 562 } 563 564 565 /** 566 * Internal function which handles adding where clauses to 567 * the query; supports AND and OR. 568 * 569 * @param $where the where term to add 570 * @param $params 571 * @param $coordinatorIsOr true if OR, false if AND 572 * @return self 573 */ 574 protected function handleWhere($where, $params = array(), $coordinatorIsOr) 575 { 576 preg_match('/^([a-z>_-])+/i', $where, $matches); 577 $search = $matches[0]; 578 $replace = $this->relationStringToDoctrineQueryColumn($search); 579 580 $where = str_replace($search, $replace, $where); 581 582 if ($coordinatorIsOr) 583 { 584 $this->q->orWhere($where, $params); 585 } 586 else 587 { 588 $this->q->addWhere($where, $params); 589 } 590 591 $this->addRelationsToQuery(); 592 593 return $this; 594 } 548 595 549 596 -
trunk/test/unit/ullCorePlugin/ullQueryTest.php
r1610 r1647 9 9 sfLoader::loadHelpers('I18N'); 10 10 11 $t = new myTestCase(2 1, new lime_output_color, $configuration);11 $t = new myTestCase(24, new lime_output_color, $configuration); 12 12 $path = sfConfig::get('sf_root_dir') . '/plugins/ullCorePlugin/data/fixtures/'; 13 13 $t->setFixturesPath($path); … … 16 16 $t->begin('__construct()'); 17 17 $q = new ullQuery('TestTable'); 18 19 20 $t->begin('__construct() with INDEXBY | Also tests limit()'); 21 $q = new ullQuery('UllUserStatus', 'slug'); 22 $q->addSelect('is_absent'); 23 $q->limit(1); 24 $t->is( 25 $q->getSqlQuery(), 26 "SELECT u.id AS u__id, u.slug AS u__slug, u.is_absent AS u__is_absent FROM ull_user_status u LIMIT 1", 27 'Created the correct SQL query' 28 ); 29 $t->is( 30 $q->execute(array(), DOCTRINE::HYDRATE_ARRAY), 31 array('active' => array('id' => 1, 'slug' => 'active', 'is_absent' => false)), 32 'Returns an indexed by array' 33 ); 18 34 19 35 … … 29 45 $t->diag('relationStringToAlias()'); 30 46 $t->is( 31 $q->relationStringToAlias('UllUser->Ull Location->Translation'),32 'x_ulluser_ull location_translation',47 $q->relationStringToAlias('UllUser->UllUserStatus->Translation'), 48 'x_ulluser_ulluserstatus_translation', 33 49 'Returns the correct string' 34 50 ); 35 51 $t->is( 36 $q->relationStringToAlias('UllUser->Ull Location', false),37 'ulluser_ull location',52 $q->relationStringToAlias('UllUser->UllUserStatus', false), 53 'ulluser_ulluserstatus', 38 54 'Returns the correct string with option prependBaseAlias = false' 39 55 ); … … 47 63 $t->diag('nestPlainArray()'); 48 64 $t->is( 49 $q->nestPlainArray(array('UllUser', 'Ull Location', 'Translation')),50 array('UllUser' => array('Ull Location' => array('Translation' => array()))),65 $q->nestPlainArray(array('UllUser', 'UllUserStatus', 'Translation')), 66 array('UllUser' => array('UllUserStatus' => array('Translation' => array()))), 51 67 'Creates the correct nested array' 52 68 ); … … 54 70 55 71 $t->diag('addRelations / getRelations()'); 56 $q->addRelations(array('UllUser', 'Ull Location', 'Translation'));72 $q->addRelations(array('UllUser', 'UllUserStatus', 'Translation')); 57 73 $t->is( 58 74 $q->getRelations(), 59 array('UllUser' => array('Ull Location' => array('Translation' => array()))),75 array('UllUser' => array('UllUserStatus' => array('Translation' => array()))), 60 76 'Returns the correct relations' 61 77 ); … … 68 84 'UllUser' => 69 85 array( 70 'Ull Location' =>86 'UllUserStatus' => 71 87 array( 72 88 'Translation' => array() … … 87 103 0 => 'TestTable x', 88 104 1 => 'x.UllUser x_ulluser', 89 2 => 'x_ulluser.Ull Location x_ulluser_ulllocation',90 3 => 'x_ulluser_ull location.Translation x_ulluser_ulllocation_translation',105 2 => 'x_ulluser.UllUserStatus x_ulluser_ulluserstatus', 106 3 => 'x_ulluser_ulluserstatus.Translation x_ulluser_ulluserstatus_translation', 91 107 4 => 'x_ulluser.UllJobTitle x_ulluser_ulljobtitle', 92 108 5 => 'x.Creator x_creator', … … 107 123 $t->is( 108 124 $q->getSqlQuery(), 109 "SELECT t.id AS t__id, t.my_email AS t__my_email, t2.id AS t2__id, t2.lang AS t2__lang, t2.my_string AS t2__my_string, u.id AS u__id, u.username AS u__username, u 2.id AS u2__id, u3.id AS u3__id, u3.lang AS u3__lang, u3.name AS u3__name, u4.id AS u4__id, u4.username AS u4__username, CONCAT('Write an email to ', t.my_email) AS t__0 FROM test_table t LEFT JOIN test_table_translation t2 ON t.id = t2.id LEFT JOIN ull_entity u ON t.ull_user_id = u.id AND u.type = 'user' LEFT JOIN ull_employment_type u2 ON u.ull_employment_type_id = u2.id LEFT JOIN ull_employment_type_translation u3 ON u2.id = u3.id LEFT JOIN ull_entity u4 ON t.creator_user_id = u4.id AND u4.type = 'user' WHERE (t2.lang = ? AND u3.lang = ?)",125 "SELECT t.id AS t__id, t.my_email AS t__my_email, t2.id AS t2__id, t2.lang AS t2__lang, t2.my_string AS t2__my_string, u.id AS u__id, u.username AS u__username, u.type AS u__type, u2.id AS u2__id, u3.id AS u3__id, u3.lang AS u3__lang, u3.name AS u3__name, u4.id AS u4__id, u4.username AS u4__username, u4.type AS u4__type, CONCAT('Write an email to ', t.my_email) AS t__0 FROM test_table t LEFT JOIN test_table_translation t2 ON t.id = t2.id LEFT JOIN ull_entity u ON t.ull_user_id = u.id AND u.type = 'user' LEFT JOIN ull_employment_type u2 ON u.ull_employment_type_id = u2.id LEFT JOIN ull_employment_type_translation u3 ON u2.id = u3.id LEFT JOIN ull_entity u4 ON t.creator_user_id = u4.id AND u4.type = 'user' WHERE (t2.lang = ? AND u3.lang = ?)", 110 126 'Returns the correct query' 111 127 ); … … 116 132 $t->is( 117 133 $q->getSqlQuery(), 118 "SELECT t.id AS t__id, t.my_email AS t__my_email, t2.id AS t2__id, t2.lang AS t2__lang, t2.my_string AS t2__my_string, u.id AS u__id, u.username AS u__username, u2.id AS u2__id, u3.id AS u3__id, u3.lang AS u3__lang, u3.name AS u3__name, u4.id AS u4__id, u4.username AS u4__username, CONCAT('Write an email to ', t.my_email) AS t__0 FROM test_table t LEFT JOIN test_table_translation t2 ON t.id = t2.id LEFT JOIN ull_entity u ON t.ull_user_id = u.id AND u.type = 'user' LEFT JOIN ull_employment_type u2 ON u.ull_employment_type_id = u2.id LEFT JOIN ull_employment_type_translation u3 ON u2.id = u3.id LEFT JOIN ull_entity u4 ON t.creator_user_id = u4.id AND u4.type = 'user' LEFT JOIN ull_location u5 ON u.ull_location_id = u5.id WHERE (t2.lang = ? AND u3.lang = ? AND t2.lang = ? AND u3.lang = ?) ORDER BY t2.my_string asc, u3.name desc, u5.name asc", 119 'Returns the correct query' 120 ); 134 "SELECT t.id AS t__id, t.my_email AS t__my_email, t2.id AS t2__id, t2.lang AS t2__lang, t2.my_string AS t2__my_string, u.id AS u__id, u.username AS u__username, u.type AS u__type, u2.id AS u2__id, u3.id AS u3__id, u3.lang AS u3__lang, u3.name AS u3__name, u4.id AS u4__id, u4.username AS u4__username, u4.type AS u4__type, CONCAT('Write an email to ', t.my_email) AS t__0 FROM test_table t LEFT JOIN test_table_translation t2 ON t.id = t2.id LEFT JOIN ull_entity u ON t.ull_user_id = u.id AND u.type = 'user' LEFT JOIN ull_employment_type u2 ON u.ull_employment_type_id = u2.id LEFT JOIN ull_employment_type_translation u3 ON u2.id = u3.id LEFT JOIN ull_entity u4 ON t.creator_user_id = u4.id AND u4.type = 'user' LEFT JOIN ull_location u5 ON u.ull_location_id = u5.id WHERE (t2.lang = ? AND u3.lang = ? AND t2.lang = ? AND u3.lang = ?) ORDER BY t2.my_string asc, u3.name desc, u5.name asc", 135 'Returns the correct query' 136 ); 137 121 138 122 139 $t->diag('addOrderByPrefix()'); … … 124 141 $t->is( 125 142 $q->getSqlQuery(), 126 "SELECT t.id AS t__id, t.my_email AS t__my_email, t2.id AS t2__id, t2.lang AS t2__lang, t2.my_string AS t2__my_string, u.id AS u__id, u.username AS u__username, u2.id AS u2__id, u3.id AS u3__id, u3.lang AS u3__lang, u3.name AS u3__name, u4.id AS u4__id, u4.username AS u4__username, CONCAT('Write an email to ', t.my_email) AS t__0 FROM test_table t LEFT JOIN test_table_translation t2 ON t.id = t2.id LEFT JOIN ull_entity u ON t.ull_user_id = u.id AND u.type = 'user' LEFT JOIN ull_employment_type u2 ON u.ull_employment_type_id = u2.id LEFT JOIN ull_employment_type_translation u3 ON u2.id = u3.id LEFT JOIN ull_entity u4 ON t.creator_user_id = u4.id AND u4.type = 'user' LEFT JOIN ull_location u5 ON u.ull_location_id = u5.id WHERE (t2.lang = ? AND u3.lang = ? AND t2.lang = ? AND u3.lang = ?) ORDER BY t.my_email asc, u5.short_name asc, t2.my_string asc, u3.name desc, u5.name asc", 127 'Returns the correct query' 128 ); 143 "SELECT t.id AS t__id, t.my_email AS t__my_email, t2.id AS t2__id, t2.lang AS t2__lang, t2.my_string AS t2__my_string, u.id AS u__id, u.username AS u__username, u.type AS u__type, u2.id AS u2__id, u3.id AS u3__id, u3.lang AS u3__lang, u3.name AS u3__name, u4.id AS u4__id, u4.username AS u4__username, u4.type AS u4__type, CONCAT('Write an email to ', t.my_email) AS t__0 FROM test_table t LEFT JOIN test_table_translation t2 ON t.id = t2.id LEFT JOIN ull_entity u ON t.ull_user_id = u.id AND u.type = 'user' LEFT JOIN ull_employment_type u2 ON u.ull_employment_type_id = u2.id LEFT JOIN ull_employment_type_translation u3 ON u2.id = u3.id LEFT JOIN ull_entity u4 ON t.creator_user_id = u4.id AND u4.type = 'user' LEFT JOIN ull_location u5 ON u.ull_location_id = u5.id WHERE (t2.lang = ? AND u3.lang = ? AND t2.lang = ? AND u3.lang = ?) ORDER BY t.my_email asc, u5.short_name asc, t2.my_string asc, u3.name desc, u5.name asc", 144 'Returns the correct query' 145 ); 146 129 147 130 148 $t->diag('addWhere()'); … … 133 151 $t->is( 134 152 $q->getSqlQuery(), 135 "SELECT t.id AS t__id, t.my_email AS t__my_email, t2.id AS t2__id, t2.lang AS t2__lang, t2.my_string AS t2__my_string, u.id AS u__id, u.username AS u__username, u 2.id AS u2__id, u3.id AS u3__id, u3.lang AS u3__lang, u3.name AS u3__name, u4.id AS u4__id, u4.username AS u4__username, CONCAT('Write an email to ', t.my_email) AS t__0 FROM test_table t LEFT JOIN test_table_translation t2 ON t.id = t2.id LEFT JOIN ull_entity u ON t.ull_user_id = u.id AND u.type = 'user' LEFT JOIN ull_employment_type u2 ON u.ull_employment_type_id = u2.id LEFT JOIN ull_employment_type_translation u3 ON u2.id = u3.id LEFT JOIN ull_entity u4 ON t.creator_user_id = u4.id AND u4.type = 'user' LEFT JOIN ull_location u5 ON u.ull_location_id = u5.id WHERE (t2.lang = ? AND u3.lang = ? AND t2.lang = ? AND u3.lang = ? AND t.my_email = ? AND u3.lang = ? AND u3.name = ?) ORDER BY t.my_email asc, u5.short_name asc, t2.my_string asc, u3.name desc, u5.name asc",153 "SELECT t.id AS t__id, t.my_email AS t__my_email, t2.id AS t2__id, t2.lang AS t2__lang, t2.my_string AS t2__my_string, u.id AS u__id, u.username AS u__username, u.type AS u__type, u2.id AS u2__id, u3.id AS u3__id, u3.lang AS u3__lang, u3.name AS u3__name, u4.id AS u4__id, u4.username AS u4__username, u4.type AS u4__type, CONCAT('Write an email to ', t.my_email) AS t__0 FROM test_table t LEFT JOIN test_table_translation t2 ON t.id = t2.id LEFT JOIN ull_entity u ON t.ull_user_id = u.id AND u.type = 'user' LEFT JOIN ull_employment_type u2 ON u.ull_employment_type_id = u2.id LEFT JOIN ull_employment_type_translation u3 ON u2.id = u3.id LEFT JOIN ull_entity u4 ON t.creator_user_id = u4.id AND u4.type = 'user' LEFT JOIN ull_location u5 ON u.ull_location_id = u5.id WHERE (t2.lang = ? AND u3.lang = ? AND t2.lang = ? AND u3.lang = ? AND t.my_email = ? AND u3.lang = ? AND u3.name = ?) ORDER BY t.my_email asc, u5.short_name asc, t2.my_string asc, u3.name desc, u5.name asc", 136 154 'Returns the correct query' 137 155 ); … … 142 160 $t->is( 143 161 $q->getSqlQuery(), 144 "SELECT t.id AS t__id, t.my_email AS t__my_email, t2.id AS t2__id, t2.lang AS t2__lang, t2.my_string AS t2__my_string, u.id AS u__id, u.username AS u__username, u2.id AS u2__id, u3.id AS u3__id, u3.lang AS u3__lang, u3.name AS u3__name, u4.id AS u4__id, u4.username AS u4__username, CONCAT('Write an email to ', t.my_email) AS t__0 FROM test_table t LEFT JOIN test_table_translation t2 ON t.id = t2.id LEFT JOIN ull_entity u ON t.ull_user_id = u.id AND u.type = 'user' LEFT JOIN ull_employment_type u2 ON u.ull_employment_type_id = u2.id LEFT JOIN ull_employment_type_translation u3 ON u2.id = u3.id LEFT JOIN ull_entity u4 ON t.creator_user_id = u4.id AND u4.type = 'user' LEFT JOIN ull_location u5 ON u.ull_location_id = u5.id WHERE (t2.lang = ? AND u3.lang = ? AND t2.lang = ? AND u3.lang = ? AND t.my_email = ? AND u3.lang = ? AND u3.name = ? OR t.my_email = ? AND u3.lang = ? OR u3.name = ?) ORDER BY t.my_email asc, u5.short_name asc, t2.my_string asc, u3.name desc, u5.name asc", 145 'Returns the correct query' 146 ); 162 "SELECT t.id AS t__id, t.my_email AS t__my_email, t2.id AS t2__id, t2.lang AS t2__lang, t2.my_string AS t2__my_string, u.id AS u__id, u.username AS u__username, u.type AS u__type, u2.id AS u2__id, u3.id AS u3__id, u3.lang AS u3__lang, u3.name AS u3__name, u4.id AS u4__id, u4.username AS u4__username, u4.type AS u4__type, CONCAT('Write an email to ', t.my_email) AS t__0 FROM test_table t LEFT JOIN test_table_translation t2 ON t.id = t2.id LEFT JOIN ull_entity u ON t.ull_user_id = u.id AND u.type = 'user' LEFT JOIN ull_employment_type u2 ON u.ull_employment_type_id = u2.id LEFT JOIN ull_employment_type_translation u3 ON u2.id = u3.id LEFT JOIN ull_entity u4 ON t.creator_user_id = u4.id AND u4.type = 'user' LEFT JOIN ull_location u5 ON u.ull_location_id = u5.id WHERE (t2.lang = ? AND u3.lang = ? AND t2.lang = ? AND u3.lang = ? AND t.my_email = ? AND u3.lang = ? AND u3.name = ? OR t.my_email = ? AND u3.lang = ? OR u3.name = ?) ORDER BY t.my_email asc, u5.short_name asc, t2.my_string asc, u3.name desc, u5.name asc", 163 'Returns the correct query' 164 ); 165 147 166 148 167 $t->isa_ok($q->execute(), 'Doctrine_Collection', 'Successfully executes the query'); … … 155 174 $t->is( 156 175 $q->getSqlQuery(), 157 "SELECT t.id AS t__id, u.id AS u__id, u2.id AS u2__id FROM test_table t LEFT JOIN test_table_translation t2 ON t.id = t2.id LEFT JOIN ull_entity u ON t.ull_user_id = u.id AND u.type = 'user' LEFT JOIN ull_employment_type u2 ON u.ull_employment_type_id = u2.id LEFT JOIN ull_employment_type_translation u3 ON u2.id = u3.id WHERE (t2.lang = ? AND u3.lang = ? AND (t.my_email LIKE ? OR t2.my_string LIKE ? OR u.username LIKE ? OR u3.name LIKE ?))", 158 'Returns the correct query' 159 ); 176 "SELECT t.id AS t__id, u.id AS u__id, u.type AS u__type, u2.id AS u2__id FROM test_table t LEFT JOIN test_table_translation t2 ON t.id = t2.id LEFT JOIN ull_entity u ON t.ull_user_id = u.id AND u.type = 'user' LEFT JOIN ull_employment_type u2 ON u.ull_employment_type_id = u2.id LEFT JOIN ull_employment_type_translation u3 ON u2.id = u3.id WHERE (t2.lang = ? AND u3.lang = ? AND (t.my_email LIKE ? OR t2.my_string LIKE ? OR u.username LIKE ? OR u3.name LIKE ?))", 177 'Returns the correct query' 178 ); 179 160 180 161 181 $t->isa_ok($q->execute(), 'Doctrine_Collection', 'Successfully executes the query'); … … 167 187 //var_dump($q->execute()->toArray(false)); 168 188 189 $t->diag('count()'); 190 $q = new ullQuery('TestTable'); 191 $t->is($q->count(), 2, 'Returns the correct number of results'); 192 193 194 $t->diag('addGroupBy()'); 195 $q = new ullQuery('UllUserStatus'); 196 $q->addSelect('COUNT(*)'); 197 $q->addGroupBy('is_absent'); 198 199 $t->is( 200 $q->getSqlQuery(), 201 "SELECT COUNT(*) AS u__0 FROM ull_user_status u GROUP BY u.is_absent", 202 'Returns the correct query' 203 ); 204 169 205 170 206 $t->diag('Doctrine 1.0 bug resolved with UllUser and SELECT on >= 2 relations'); … … 179 215 $q->execute(); 180 216 181 $t->diag('count()'); 182 $q = new ullQuery('TestTable'); 183 $t->is($q->count(), 2, 'Returns the correct number of results'); 217 184 218 185 219
