getPrimaryKey() public method

public getPrimaryKey ( string $table ) : string
$table string
return string
Exemplo n.º 1
0
 /**
  * Create SELECT query from $table
  *
  * @param string  $table      - db table name
  * @param integer $primaryKey - return one row by primary key
  *
  * @return \SelectQuery
  */
 public function from($table, $primaryKey = null)
 {
     $query = new SelectQuery($this, $table);
     if ($primaryKey !== null) {
         $tableTable = $query->getFromTable();
         $tableAlias = $query->getFromAlias();
         $primaryKeyName = $this->structure->getPrimaryKey($tableTable);
         $query = $query->where("{$tableAlias}.{$primaryKeyName}", $primaryKey);
     }
     return $query;
 }
Exemplo n.º 2
0
 /** Create join string
  * @return string 
  */
 private function createJoin($clause, $mainTable, $joinTable, $joinAlias = '')
 {
     if (in_array(substr($mainTable, -1), array(':', '.'))) {
         $mainTable = substr($mainTable, 0, -1);
     }
     $referenceDirection = substr($joinTable, -1);
     $joinTable = substr($joinTable, 0, -1);
     $asJoinAlias = '';
     if ($joinAlias) {
         $asJoinAlias = " AS {$joinAlias}";
         if (!in_array($joinAlias, $this->createdAliases)) {
             $this->createdAliases[] = $joinAlias;
         }
     } else {
         $joinAlias = $joinTable;
     }
     if ($referenceDirection == ':') {
         # back reference
         $primaryKey = $this->structure->getPrimaryKey($mainTable);
         $foreignKey = $this->structure->getForeignKey($mainTable);
         return " {$clause} {$joinTable}{$asJoinAlias} ON {$joinAlias}.{$foreignKey} = {$mainTable}.{$primaryKey}";
     } else {
         $primaryKey = $this->structure->getPrimaryKey($joinTable);
         $foreignKey = $this->structure->getForeignKey($joinTable);
         return " {$clause} {$joinTable}{$asJoinAlias} ON {$joinAlias}.{$primaryKey} = {$mainTable}.{$foreignKey}";
     }
 }