コード例 #1
0
ファイル: Relation.php プロジェクト: wave-framework/wave
 /**
  * Returns the name of the relation.  It needs to be based on the column name as if there
  * is more than one relation to the same table, the relation won't have a unique name.
  * If the column ends with '_id', it will be removed.
  **/
 public function getName()
 {
     //$local_column
     switch ($this->type) {
         case self::ONE_TO_ONE:
             $name = $this->getReferencedTable()->getName();
             break;
         case self::MANY_TO_ONE:
             //in this case we need to name the relation based on the column, trimming off _id (if it exists)
             $name = $this->local_columns[0]->getName();
             if (substr($name, -3) === '_id') {
                 $name = substr($name, 0, -3);
             }
             break;
         case self::ONE_TO_MANY:
             //slightly more complex to remove collisions between m2m names
             $name = Wave\Inflector::pluralize($this->getReferencedTable()->getName());
             $ref_name = $this->referenced_columns[0]->getName();
             if (substr($ref_name, -3) === '_id') {
                 $ref_name = substr($ref_name, 0, -3);
             }
             if ($ref_name !== $this->getLocalTable()->getName()) {
                 $name .= '_' . $ref_name;
             }
             break;
         case self::MANY_TO_MANY:
             $columns = $this->target_relation->getLocalColumns();
             $name = $columns[0]->getMetadata('relation_name');
             if ($name === null) {
                 $name = $this->target_relation->getReferencedTable()->getName();
             }
             $name = Wave\Inflector::pluralize($name);
             break;
     }
     return Wave\Inflector::camelize($name);
 }