->from('Record_Country c')->innerJoin('c.City c2 ON c2.id = 2')
->where('c.id = ?',array(1));
$this->assertEqual($q->getSql(),'SELECT r.id AS r__id, r.name AS r__name, r2.id AS r2__id, r2.name AS r2__name, r2.country_id AS r2__country_id, r2.district_id AS r2__district_id FROM record__country r INNER JOIN record__city r2 ON r2.id = 2 WHERE r.id = ?');
->from('Record_Country c')->innerJoin('c.City c2 WITH c2.id = 2')
->where('c.id = ?',array(1));
$this->assertEqual($q->getSql(),'SELECT r.id AS r__id, r.name AS r__name, r2.id AS r2__id, r2.name AS r2__name, r2.country_id AS r2__country_id, r2.district_id AS r2__district_id FROM record__country r INNER JOIN record__city r2 ON r.id = r2.country_id AND r2.id = 2 WHERE r.id = ?');
$this->assertEqual($q->getQuery(),"SELECT r.id AS r__id, r.name AS r__name, r2.id AS r2__id, r2.name AS r2__name, r2.country_id AS r2__country_id, r2.district_id AS r2__district_id, r3.id AS r3__id, r3.name AS r3__name FROM record__country r LEFT JOIN record__city r2 ON r.id = r2.country_id LEFT JOIN record__district r3 ON r2.district_id = r3.id WHERE r.id = ?");
$q->select('u.name')->from('User u INNER JOIN u.Group g');
$this->assertEqual($q->getQuery(),'SELECT e.id AS e__id, e.name AS e__name FROM entity e INNER JOIN groupuser g ON e.id = g.user_id INNER JOIN entity e2 ON e2.id = g.group_id WHERE (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL))');
$this->assertEqual($q->getQuery(),'SELECT e.id AS e__id, e.name AS e__name FROM entity e INNER JOIN entity_reference e3 ON e.id = e3.entity1 OR e.id = e3.entity2 INNER JOIN entity e2 ON (e2.id = e3.entity2 OR e2.id = e3.entity1) AND e2.id != e.id');
$this->assertEqual($q->getQuery(),'SELECT e.id AS e__id, e2.id AS e2__id, e3.id AS e3__id FROM entity e LEFT JOIN groupuser g ON e.id = g.user_id LEFT JOIN entity e2 ON e2.id = g.group_id LEFT JOIN email e3 ON e2.email_id = e3.id WHERE (e.type = 0 AND (e2.type = 1 OR e2.type IS NULL))');
$this->assertEqual($q->getQuery(),'SELECT e.id AS e__id, e2.id AS e2__id FROM entity e LEFT JOIN groupuser g ON e.id = g.group_id LEFT JOIN entity e2 ON e2.id = g.user_id LEFT JOIN account a ON e2.id = a.entity_id WHERE (e.type = 1 AND (e2.type = 0 OR e2.type IS NULL))');