Ticket #870: generator-15b1-patch.diff

File generator-15b1-patch.diff, 5.5 KB (added by lvanderree, 6 months ago)

patch for generator folder

  • lib/builder/om/PHP5TableMapBuilder.php

     
    268268      $columnMapping .= ')'; 
    269269      $onDelete = $fkey->hasOnDelete() ? "'" . $fkey->getOnDelete() . "'" : 'null'; 
    270270      $onUpdate = $fkey->hasOnUpdate() ? "'" . $fkey->getOnUpdate() . "'" : 'null'; 
     271      $preferedJoinType = $fkey->hasPreferedJoinType() ? "'" . $fkey->getPreferedJoinType() . "'" : 'null'; 
    271272      $script .= " 
    272     \$this->addRelation('" . $this->getFKPhpNameAffix($fkey) . "', '" . $fkey->getForeignTable()->getPhpName() . "', RelationMap::MANY_TO_ONE, $columnMapping, $onDelete, $onUpdate);"; 
     273    \$this->addRelation('" . $this->getFKPhpNameAffix($fkey) . "', '" . $fkey->getForeignTable()->getPhpName() . "', RelationMap::MANY_TO_ONE, $columnMapping, $onDelete, $onUpdate, $preferedJoinType);"; 
    273274    } 
    274275    foreach ($this->getTable()->getReferrers() as $fkey) 
    275276    { 
     
    281282      $columnMapping .= ')'; 
    282283      $onDelete = $fkey->hasOnDelete() ? "'" . $fkey->getOnDelete() . "'" : 'null'; 
    283284      $onUpdate = $fkey->hasOnUpdate() ? "'" . $fkey->getOnUpdate() . "'" : 'null'; 
     285      $preferedJoinType = $fkey->hasPreferedJoinType() ? "'" . $fkey->getPreferedJoinType() . "'" : 'null'; 
    284286      $script .= " 
    285     \$this->addRelation('" . $this->getRefFKPhpNameAffix($fkey) . "', '" . $fkey->getTable()->getPhpName() . "', RelationMap::ONE_TO_" . ($fkey->isLocalPrimaryKey() ? "ONE" : "MANY") .", $columnMapping, $onDelete, $onUpdate);"; 
     287    \$this->addRelation('" . $this->getRefFKPhpNameAffix($fkey) . "', '" . $fkey->getTable()->getPhpName() . "', RelationMap::ONE_TO_" . ($fkey->isLocalPrimaryKey() ? "ONE" : "MANY") .", $columnMapping, $onDelete, $onUpdate, $preferedJoinType);"; 
    286288    } 
    287289    foreach ($this->getTable()->getCrossFks() as $fkList) 
    288290    { 
    289291      list($refFK, $crossFK) = $fkList; 
    290292      $onDelete = $fkey->hasOnDelete() ? "'" . $fkey->getOnDelete() . "'" : 'null'; 
    291293      $onUpdate = $fkey->hasOnUpdate() ? "'" . $fkey->getOnUpdate() . "'" : 'null'; 
     294      $preferedJoinType = $fkey->hasPreferedJoinType() ? "'" . $fkey->getPreferedJoinType() . "'" : 'null'; 
    292295      $script .= " 
    293     \$this->addRelation('" . $this->getFKPhpNameAffix($crossFK) . "', '" . $crossFK->getForeignTable()->getPhpName() . "', RelationMap::MANY_TO_MANY, array(), $onDelete, $onUpdate);"; 
     296    \$this->addRelation('" . $this->getFKPhpNameAffix($crossFK) . "', '" . $crossFK->getForeignTable()->getPhpName() . "', RelationMap::MANY_TO_MANY, array(), $onDelete, $onUpdate, $preferedJoinType);"; 
    294297    } 
    295298    $script .= " 
    296299        } // buildRelations() 
  • lib/model/ForeignKey.php

     
    3939        protected $refPhpName; 
    4040        protected $onUpdate; 
    4141        protected $onDelete; 
     42        protected $preferedJoinType; 
    4243        protected $parentTable; 
    4344        protected $localColumns = array(); 
    4445        protected $foreignColumns = array(); 
     
    5051        const RESTRICT = "RESTRICT"; 
    5152        const SETDEFAULT  = "SET DEFAULT"; 
    5253        const SETNULL  = "SET NULL"; 
     54        const INNERJOIN = "INNER JOIN"; 
    5355 
    5456        /** 
    5557         * Constructs a new ForeignKey object. 
     
    7375                $this->refPhpName = $this->getAttribute("refPhpName"); 
    7476                $this->onUpdate = $this->normalizeFKey($this->getAttribute("onUpdate")); 
    7577                $this->onDelete = $this->normalizeFKey($this->getAttribute("onDelete")); 
     78                $this->preferedJoinType = $this->getAttribute("preferedJoinType"); 
    7679        } 
    7780 
    7881        /** 
     
    98101                return ($this->onUpdate !== self::NONE); 
    99102        } 
    100103 
     104  /** 
     105   * returns whether or not the preferedJoinType attribute is set 
     106   */ 
     107  public function hasPreferedJoinType() 
     108  { 
     109    return ($this->preferedJoinType !== self::NONE); 
     110  } 
     111         
    101112        /** 
    102113         * returns whether or not the onDelete attribute is set 
    103114         */ 
     
    114125        { 
    115126                return $this->onUpdate; 
    116127        } 
     128         
     129 /** 
     130   * returns the preferedJoinType attribute 
     131   * @return     string 
     132   */ 
     133  public function getPreferedJoinType() 
     134  { 
     135    return $this->preferedJoinType ? $this->preferedJoinType : self::INNERJOIN; 
     136  } 
    117137 
    118138        /** 
    119139         * Returns the onDelete attribute 
     
    139159        { 
    140160                $this->onUpdate = $this->normalizeFKey($value); 
    141161        } 
    142  
     162         
     163  /** 
     164   * sets the preferedJoinType attribute 
     165   */ 
     166  public function setPreferedJoinType($value) 
     167  { 
     168    $this->preferedJoinType = $value; 
     169  } 
     170   
    143171        /** 
    144172         * Returns the name attribute. 
    145173         */ 
     
    456484                        $fkNode->setAttribute('onUpdate', $this->getOnUpdate()); 
    457485                } 
    458486                 
     487                if ($this->getPreferedJoinType()) { 
     488      $fkNode->setAttribute('preferedJoinType', $this->getPreferedJoinType()); 
     489    } 
     490                 
    459491                for ($i=0, $size=count($this->localColumns); $i < $size; $i++) { 
    460492                        $refNode = $fkNode->appendChild($doc->createElement('reference')); 
    461493                        $refNode->setAttribute('local', $this->localColumns[$i]); 
  • resources/xsd/database.xsd

     
    335335                <xs:attribute name="name" type="foreign_name" use="optional"/> 
    336336                <xs:attribute name="phpName" type="php_name" use="optional"/> 
    337337                <xs:attribute name="refPhpName" type="php_name" use="optional"/> 
     338    <xs:attribute name="preferedJoinType" type="xs:string" use="optional"/> 
    338339                <xs:attribute name="onDelete" type="delete" default="none"/> 
    339340                <xs:attribute name="onUpdate" type="update" default="none"/> 
    340341        </xs:complexType>