当前位置: 首页>>代码示例>>PHP>>正文


PHP SQLSelect::isJoinedTo方法代码示例

本文整理汇总了PHP中SQLSelect::isJoinedTo方法的典型用法代码示例。如果您正苦于以下问题:PHP SQLSelect::isJoinedTo方法的具体用法?PHP SQLSelect::isJoinedTo怎么用?PHP SQLSelect::isJoinedTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SQLSelect的用法示例。


在下文中一共展示了SQLSelect::isJoinedTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: joinHasManyRelation

 /**
  * Join the given has_many relation to this query.
  *
  * Doesn't work with polymorphic relationships
  *
  * @param string $localClass Name of class that has the has_many to the joined class
  * @param string $localField Name of the has_many relationship to join
  * @param string $foreignClass Class to join
  */
 protected function joinHasManyRelation($localClass, $localField, $foreignClass)
 {
     if (!$foreignClass || $foreignClass === 'DataObject') {
         throw new InvalidArgumentException("Could not find a has_many relationship {$localField} on {$localClass}");
     }
     // Skip if already joined
     if ($this->query->isJoinedTo($foreignClass)) {
         return;
     }
     // Join table with associated has_one
     $model = singleton($localClass);
     $ancestry = $model->getClassAncestry();
     $foreignKey = $model->getRemoteJoinField($localField, 'has_many', $polymorphic);
     if ($polymorphic) {
         $this->query->addLeftJoin($foreignClass, "\"{$foreignClass}\".\"{$foreignKey}ID\" = \"{$ancestry[0]}\".\"ID\" AND " . "\"{$foreignClass}\".\"{$foreignKey}Class\" = \"{$ancestry[0]}\".\"ClassName\"");
     } else {
         $this->query->addLeftJoin($foreignClass, "\"{$foreignClass}\".\"{$foreignKey}\" = \"{$ancestry[0]}\".\"ID\"");
     }
     /**
      * add join clause to the component's ancestry classes so that the search filter could search on
      * its ancestor fields.
      */
     $ancestry = ClassInfo::ancestry($foreignClass, true);
     $ancestry = array_reverse($ancestry);
     foreach ($ancestry as $ancestor) {
         if ($ancestor != $foreignClass) {
             $this->query->addInnerJoin($ancestor, "\"{$foreignClass}\".\"ID\" = \"{$ancestor}\".\"ID\"");
         }
     }
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:39,代码来源:DataQuery.php

示例2: applyRelation

 /**
  * Traverse the relationship fields, and add the table
  * mappings to the query object state. This has to be called
  * in any overloaded {@link SearchFilter->apply()} methods manually.
  *
  * @param String|array $relation The array/dot-syntax relation to follow
  * @return The model class of the related item
  */
 public function applyRelation($relation)
 {
     // NO-OP
     if (!$relation) {
         return $this->dataClass;
     }
     if (is_string($relation)) {
         $relation = explode(".", $relation);
     }
     $modelClass = $this->dataClass;
     foreach ($relation as $rel) {
         $model = singleton($modelClass);
         if ($component = $model->has_one($rel)) {
             if (!$this->query->isJoinedTo($component)) {
                 $foreignKey = $model->getReverseAssociation($component);
                 $this->query->addLeftJoin($component, "\"{$component}\".\"ID\" = \"{$modelClass}\".\"{$foreignKey}ID\"");
                 /**
                  * add join clause to the component's ancestry classes so that the search filter could search on
                  * its ancestor fields.
                  */
                 $ancestry = ClassInfo::ancestry($component, true);
                 if (!empty($ancestry)) {
                     $ancestry = array_reverse($ancestry);
                     foreach ($ancestry as $ancestor) {
                         if ($ancestor != $component) {
                             $this->query->addInnerJoin($ancestor, "\"{$component}\".\"ID\" = \"{$ancestor}\".\"ID\"");
                         }
                     }
                 }
             }
             $modelClass = $component;
         } elseif ($component = $model->has_many($rel)) {
             if (!$this->query->isJoinedTo($component)) {
                 $ancestry = $model->getClassAncestry();
                 $foreignKey = $model->getRemoteJoinField($rel);
                 $this->query->addLeftJoin($component, "\"{$component}\".\"{$foreignKey}\" = \"{$ancestry[0]}\".\"ID\"");
                 /**
                  * add join clause to the component's ancestry classes so that the search filter could search on
                  * its ancestor fields.
                  */
                 $ancestry = ClassInfo::ancestry($component, true);
                 if (!empty($ancestry)) {
                     $ancestry = array_reverse($ancestry);
                     foreach ($ancestry as $ancestor) {
                         if ($ancestor != $component) {
                             $this->query->addInnerJoin($ancestor, "\"{$component}\".\"ID\" = \"{$ancestor}\".\"ID\"");
                         }
                     }
                 }
             }
             $modelClass = $component;
         } elseif ($component = $model->many_many($rel)) {
             list($parentClass, $componentClass, $parentField, $componentField, $relationTable) = $component;
             $parentBaseClass = ClassInfo::baseDataClass($parentClass);
             $componentBaseClass = ClassInfo::baseDataClass($componentClass);
             $this->query->addInnerJoin($relationTable, "\"{$relationTable}\".\"{$parentField}\" = \"{$parentBaseClass}\".\"ID\"");
             $this->query->addLeftJoin($componentBaseClass, "\"{$relationTable}\".\"{$componentField}\" = \"{$componentBaseClass}\".\"ID\"");
             if (ClassInfo::hasTable($componentClass)) {
                 $this->query->addLeftJoin($componentClass, "\"{$relationTable}\".\"{$componentField}\" = \"{$componentClass}\".\"ID\"");
             }
             $modelClass = $componentClass;
         }
     }
     return $modelClass;
 }
开发者ID:congaaids,项目名称:silverstripe-framework,代码行数:73,代码来源:DataQuery.php


注:本文中的SQLSelect::isJoinedTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。