$this->parts["join"][$tname][$assocTableName]=$join.$assocTableName." ON ".$tname.".".$table->getIdentifier()." = ".$assocTableName.".".$fk->getLocal();
$this->parts["join"][$tname][$tname2]=$join.$aliasString." ON ".$tname2.".".$table->getIdentifier()." = ".$assocTableName.".".$fk->getForeign();
$this->parts["join"][$tname][$assocTableName]=$join.$assocTableName.' ON '.$tname.".".$table->getIdentifier()." = ".$assocTableName.".".$fk->getLocal();
$this->parts["join"][$tname][$tname2]=$join.$aliasString.' ON '.$tname2.".".$table->getIdentifier()." = ".$assocTableName.".".$fk->getForeign();
}else{
$this->parts["join"][$tname][$tname2]=$join.$aliasString.' ON '.$tname.".".$fk->getLocal()." = ".$tname2.".".$fk->getForeign();
$q->parseQuery('SELECT MAX(u.id), MIN(u.name), COUNT(p.id) FROM User u, u.Phonenumber p');
$this->assertEqual($q->getQuery(),'SELECT MAX(entity.id) AS entity__0, MIN(entity.name) AS entity__1, COUNT(phonenumber.id) AS phonenumber__2 FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE (entity.type = 0)');
$this->assertEqual($q->getQuery(),'SELECT entity.id AS entity__id, entity.name AS entity__name, entity.loginname AS entity__loginname, entity.password AS entity__password, entity.type AS entity__type, entity.created AS entity__created, entity.updated AS entity__updated, entity.email_id AS entity__email_id FROM entity WHERE (entity.type = 0)');
$q->parseQuery('SELECT u.name, u.type FROM User u');
$this->assertEqual($q->getQuery(),'SELECT entity.id AS entity__id, entity.name AS entity__name, entity.type AS entity__type FROM entity WHERE (entity.type = 0)');
$q->parseQuery('SELECT u.*, p.* FROM User u, u.Phonenumber p');
$this->assertEqual($q->getQuery(),'SELECT entity.id AS entity__id, entity.name AS entity__name, entity.loginname AS entity__loginname, entity.password AS entity__password, entity.type AS entity__type, entity.created AS entity__created, entity.updated AS entity__updated, entity.email_id AS entity__email_id, phonenumber.id AS phonenumber__id, phonenumber.phonenumber AS phonenumber__phonenumber, phonenumber.entity_id AS phonenumber__entity_id FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE (entity.type = 0)');
$q->parseQuery('SELECT u.id, u.name, p.id FROM User u, u.Phonenumber p');
$this->assertEqual($q->getQuery(),'SELECT entity.id AS entity__id, entity.name AS entity__name, phonenumber.id AS phonenumber__id FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE (entity.type = 0)');