/** * * @return Oops_Sql_Selector */ private function _getSelector() { if (!isset($this->_selector)) { $this->_selector = new Oops_Sql_Selector($this->_table, null, array('target', 'source')); } else { $this->_selector->resetAll(); } return $this->_selector; }
public function testJoin() { $this->Oops_Sql_Selector->resetAll(); $jSelector = new Oops_Sql_Selector('testDatabase.joinTable', 'testField2', array('testFieldX', 'testFieldY')); $this->Oops_Sql_Selector->join($jSelector, 'testField2', 'testField2', Oops_Sql_Selector::JOIN_LEFT); $this->assertEquals("SELECT COUNT(*) FROM `testDatabase`.`testTable` AS `t1` LEFT JOIN `testDatabase`.`joinTable` AS `t2` ON `t1`.`testField2` = `t2`.`testField2`", $this->Oops_Sql_Selector->count(true)); $this->Oops_Sql_Selector->resetJoins(); $this->Oops_Sql_Selector->join($jSelector, 'testField2', 'testField2', Oops_Sql_Selector::JOIN_LEFT, 'joiny'); $this->assertEquals("SELECT COUNT(*) FROM `testDatabase`.`testTable` AS `t1` LEFT JOIN `testDatabase`.`joinTable` AS `joiny` ON `t1`.`testField2` = `joiny`.`testField2`", $this->Oops_Sql_Selector->count(true)); $jj = clone $jSelector; $jSelector->join($jj, 'testFieldX', 'testFieldY', Oops_Sql_Selector::JOIN_INNER, 'joiny'); $this->assertEquals("SELECT COUNT(*) FROM `testDatabase`.`testTable` AS `t1` LEFT JOIN (`testDatabase`.`joinTable` AS `joiny`, `testDatabase`.`joinTable` AS `t2`) ON `t1`.`testField2` = `joiny`.`testField2` WHERE `joiny`.`testFieldX` = `t2`.`testFieldY`", $this->Oops_Sql_Selector->count(true)); }