Development

Changeset 10102

You must first sign up to be able to contribute.

Changeset 10102

Show
Ignore:
Timestamp:
07/03/08 18:22:02 (5 years ago)
Author:
francois
Message:

sfPropelFinderPlugin Harmonized class<->peerClass conversions

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelFinderPlugin/lib/sfPropelFinder.php

    r10101 r10102  
    556556      call_user_func(array($tempClass->getPeer(), 'addSelectColumns'), $c); 
    557557      // if join() wasn't called previously on this class, do a simple join 
    558       if(!in_array($className.'Peer', $this->relations)) 
     558      if(!in_array($this->getPeerClassFromClass($className), $this->relations)) 
    559559      { 
    560560        list($column1, $column2) = $this->getRelation($className); 
    561561        $c->addJoin($column1, $column2); 
    562         $this->relations[]= $className.'Peer'
     562        $this->relations[]= $this->getPeerClassFromClass($className)
    563563      } 
    564564    } 
     
    571571      if($peerClass && !in_array($peerClass, $this->relations)) 
    572572      { 
    573         list($column1, $column2) = $this->getRelation(str_replace('Peer', '', $peerClass)); 
     573        list($column1, $column2) = $this->getRelation($this->getClassFromPeerClass($peerClass)); 
    574574        $c->addJoin($column1, $column2); 
    575575        $this->relations[]= $peerClass; 
     
    942942  { 
    943943    list($column1, $column2) = $this->getRelation($relatedClass); 
    944     $this->relations[]= $relatedClass.'Peer'
     944    $this->relations[]= $this->getPeerClassFromClass($relatedClass)
    945945    if(!is_array($arguments)) 
    946946    { 
     
    968968      } 
    969969      // try to find one to many relationship 
    970       if($relation = $this->findRelation(str_replace('Peer', '', $peerClass), $phpName.'Peer')) 
     970      if($relation = $this->findRelation( 
     971        $this->getClassFromPeerClass($peerClass), 
     972        $this->getPeerClassFromClass($phpName))) 
    971973      { 
    972974        return array_reverse($relation); 
     
    982984      if ($c->isForeignKey()) 
    983985      { 
    984         try 
    985         { 
    986           $tableMap = $this->databaseMap->getTable($c->getRelatedTableName()); 
    987         } 
    988         catch (PropelException $e) 
    989         { 
    990           // So this table map hasn't been built yet, let's build it 
    991           $tmp = new $phpName(); 
    992           $relatedPeerClass = get_class($tmp->getPeer()); 
    993           $mapBuilder = call_user_func(array($relatedPeerClass, 'getMapBuilder'));  
     986        if(!$this->databaseMap->containsTable($c->getRelatedTableName())) 
     987        { 
     988          $mapBuilder = call_user_func(array($this->getPeerClassFromClass($phpName), 'getMapBuilder'));  
    994989          $mapBuilder->doBuild(); 
    995           $tableMap = $this->databaseMap->getTable($c->getRelatedTableName()); 
    996         } 
    997         if($tableMap->getPhpName() == $phpName) 
     990        } 
     991        if($this->databaseMap->getTable($c->getRelatedTableName())->getPhpName() == $phpName) 
    998992        { 
    999993          return array( 
     
    10081002  } 
    10091003   
     1004  protected function getPeerClassFromClass($class) 
     1005  { 
     1006    $tmp = new $class(); 
     1007    return get_class($tmp->getPeer()); 
     1008  } 
     1009 
     1010  protected function getClassFromPeerClass($peerClass) 
     1011  { 
     1012    $omClass = call_user_func(array($peerClass, 'getOMClass')); 
     1013    return substr('.'.$omClass, strrpos('.'.$omClass, '.') + 1); 
     1014  } 
     1015   
    10101016  /** 
    10111017   * Behavior-like supplementary getter for supplementary columns added by way of withColumn() 
     
    10471053    { 
    10481054      list($class, $phpName) = split('_', $phpName); 
    1049       $peerClass = $class.'Peer'
     1055      $peerClass = $this->getPeerClassFromClass($class)
    10501056    } 
    10511057    if(!$peerClass)