Changeset 4492
- Timestamp:
- 06/08/08 19:23:14 (13 months ago)
- Files:
-
- 1 modified
-
branches/0.11/tests/Ticket/1121TestCase.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.11/tests/Ticket/1121TestCase.php
r4490 r4492 44 44 $q = Doctrine_Query::create() 45 45 ->from('Ticket_1121_User u') 46 ->leftJoin('u.CustomProfileAlias p'); 46 // UserProfile has SoftDelete behavior but because it is aliased as Profile, it tries to 47 // call the dql callbacks for the query on a class named Profile instead of UserProfile 48 // Code responsible for this is in Doctrine_Query_Abstract::_preQuery() 49 ->leftJoin('u.Profile p'); 47 50 48 try { 49 $q->execute(); 50 $this->pass(); 51 } catch (Exception $e) { 52 $this->fail($e->getMessage()); 53 } 54 55 } 56 } 57 58 spl_autoload_register(array('Ticket_1121_Autoloader', 'autoload')); 59 60 class Ticket_1121_Autoloader 61 { 62 public static function autoload($className) 63 { 64 // You will see the above query is parsing the from parts of the query 65 if ($className == 'CustomProfileAlias' || $className == 'CustomUserAlias') { 66 throw new Exception('DQL callbacks being called for CustomProfileAlias and CustomUserAlias. These are the relationship aliases, not the class name in this case'); 67 } 51 // The condition and params for UserProfile SoftDelete and are not added properly 52 $this->assertEqual($q->getSql(), 'SELECT t.id AS t__id, t.username AS t__username, t.password AS t__password, t.profile_id AS t__profile_id, t.deleted AS t__deleted, t2.id AS t2__id, t2.name AS t2__name, t2.about AS t2__about, t2.deleted AS t2__deleted FROM ticket_1121__user t LEFT JOIN ticket_1121__profile t2 ON t.profile_id = t2.id WHERE t.deleted = ? AND t2.deleted = ?'); 53 $this->assertEqual(count($q->getParams()), 2); 68 54 } 69 55 } … … 80 66 public function setUp() 81 67 { 82 $this->hasOne('Ticket_1121_Profile as CustomProfileAlias', array('local' => 'profile_id', 68 $this->actAs('SoftDelete'); 69 $this->hasOne('Ticket_1121_Profile as Profile', array('local' => 'profile_id', 83 70 'foreign' => 'id')); 84 71 } … … 91 78 $this->hasColumn('name', 'string', 255); 92 79 $this->hasColumn('about', 'string', 2000); 93 $this->hasColumn('active', 'integer');94 $this->addListener(new Ticket_1121_Profile_Listener());95 80 } 96 81 97 82 public function setUp() 98 83 { 99 $this->hasOne('Ticket_1121_User as CustomUserAlias', array('local' => 'id', 84 $this->actAs('SoftDelete'); 85 $this->hasOne('Ticket_1121_User as User', array('local' => 'id', 100 86 'foreign' => 'profile_id')); 101 87 } 102 88 } 103 104 class Ticket_1121_Profile_Listener extends Doctrine_Record_Listener105 {106 public function preDqlSelect(Doctrine_Event $event)107 {108 $params = $event->getParams();109 $field = $params['alias'] . '.active';110 111 $event->getQuery()->addWhere($field . ' = ?', 1);112 }113 }