/**
  * go through the fetechmode array and transform it to a tree
  * collect JoinPart objects
  *
  * @param   string[] path
  * @param   rdbms.join.JoinPart current joinpart
  * @param   string[] curpath
  * @throws  lang.IllegalArgumentException
  */
 private function transformFetchmode(array $path, JoinPart $sjp, $curpath = [])
 {
     if (0 == sizeof($path)) {
         return;
     }
     $role = array_shift($path);
     if (!isset($sjp->peer->relations[$role])) {
         throw new \lang\IllegalArgumentException($role . ': no such role for ' . $sjp->peer->identifier . ' - try one of ' . implode(', ', array_keys($sjp->peer->relations)));
     }
     $curpath[] = $role;
     $key = self::pathToKey($curpath);
     if (!isset($this->joinparts[$key])) {
         $this->joinparts[$key] = new JoinPart($key, \lang\XPClass::forName($sjp->peer->relations[$role]['classname'])->getMethod('getPeer')->invoke(null));
     }
     $sjp->addRelative($this->joinparts[$key], $role);
     $this->transformFetchmode($path, $this->joinparts[$key], $curpath);
 }
 public function extractTest()
 {
     $toJob = new JoinPart('j', Job::getPeer());
     $toPerson = new JoinPart('p', Person::getPeer());
     $toDepartment = new JoinPart('d', Department::getPeer());
     $toChief = new JoinPart('c', Person::getPeer());
     $toJob->addRelative($toPerson, 'JobPerson');
     $toPerson->addRelative($toDepartment, 'Department');
     $toDepartment->addRelative($toChief, 'DepartmentChief');
     $job = Job::getPeer()->objectFor(array('job_id' => '21', 'title' => 'clean the toilette', 'valid_from' => new Date(), 'expire_at' => ''));
     $toPerson->extract($job, array('p_person_id' => '11', 'p_name' => 'Schultz', 'p_job_id' => '21', 'p_department_id' => '31', 'd_department_id' => '31', 'd_name' => 'iDev', 'd_chief_id' => '12', 'c_person_id' => '12', 'c_name' => 'Friebe', 'c_job_id' => '22', 'c_department_id' => '31'), 'JobPerson');
     $this->assertClass($job->getCachedObj('JobPerson', '#11'), 'net.xp_framework.unittest.rdbms.dataset.Person');
     $this->assertClass($job->getCachedObj('JobPerson', '#11')->getCachedObj('Department', '#31'), 'net.xp_framework.unittest.rdbms.dataset.Department');
     $this->assertClass($job->getCachedObj('JobPerson', '#11')->getCachedObj('Department', '#31')->getCachedObj('DepartmentChief', '#12'), 'net.xp_framework.unittest.rdbms.dataset.Person');
 }