Beispiel #1
0
 private function _join(JoinClause $join, $table, $sourceField, $destField = null, $where = null)
 {
     /**
      * @var $this IStatement
      */
     if ($destField === null) {
         $destField = $sourceField;
     }
     $from = $this->getClause('FROM');
     if ($from instanceof FromClause) {
         $sourceTable = $from->getTable();
         if ($sourceTable instanceof TableSelectExpression) {
             /** @var TableSelectExpression $sourceTable */
             $sourceTable = $sourceTable->getAlias();
         } else {
             if ($sourceTable instanceof TableExpression) {
                 /** @var TableExpression $sourceTable */
                 $sourceTable = $sourceTable->getTableName();
             }
         }
     } else {
         throw new \RuntimeException("Unable to join on a statement without a from clause being specified");
     }
     $join->setTableName($table);
     $join->setDestinationField($table, $destField);
     $join->setSourceField($sourceTable, $sourceField);
     if ($where !== null) {
         $join->setPredicates(WhereClause::buildPredicates($where, $table));
     }
     $this->addClause($join);
     return $this;
 }