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


PHP Relation::getHasCompareKey方法代码示例

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


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

示例1: addHasWhere

 /**
  * Add the "has" condition where clause to the query.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $hasQuery
  * @param  \Illuminate\Database\Eloquent\Relations\Relation  $relation
  * @param  string  $operator
  * @param  int  $count
  * @param  string  $boolean
  * @return \Illuminate\Database\Eloquent\Builder
  */
 protected function addHasWhere(EloquentBuilder $hasQuery, Relation $relation, $operator, $count, $boolean)
 {
     $query = $hasQuery->getQuery();
     // Get the number of related objects for each possible parent.
     $relationCount = array_count_values($query->lists($relation->getHasCompareKey()));
     // Remove unwanted related objects based on the operator and count.
     $relationCount = array_filter($relationCount, function ($counted) use($count, $operator) {
         // If we are comparing to 0, we always need all results.
         if ($count == 0) {
             return true;
         }
         switch ($operator) {
             case '>=':
             case '<':
                 return $counted >= $count;
             case '>':
             case '<=':
                 return $counted > $count;
             case '=':
             case '!=':
                 return $counted == $count;
         }
     });
     // If the operator is <, <= or !=, we will use whereNotIn.
     $not = in_array($operator, array('<', '<=', '!='));
     // If we are comparing to 0, we need an additional $not flip.
     if ($count == 0) {
         $not = !$not;
     }
     // All related ids.
     $relatedIds = array_keys($relationCount);
     // Add whereIn to the query.
     return $this->whereIn($this->model->getKeyName(), $relatedIds, $boolean, $not);
 }
开发者ID:reverserob,项目名称:laravel-mongodb,代码行数:44,代码来源:Builder.php


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