示例#1
0
 public function loadModels(Models $models, $flags = null)
 {
     $models = $models->filter(function ($model) {
         return $model->{$this->classKey};
     });
     $groups = Arr::groupBy($models->toArray(), function ($model) {
         return $model->{$this->classKey};
     });
     foreach ($groups as $modelClass => &$models) {
         $keys = Arr::pluckUniqueProperty($models, $this->key);
         if ($keys) {
             $models = $modelClass::whereIn($this->getForeignKey(), $keys)->setFlags($flags)->loadRaw();
         } else {
             $models = [];
         }
     }
     return Arr::flatten($groups);
 }
示例#2
0
 /**
  * @param  array|string $rels
  */
 public function joinRels($rels)
 {
     $rels = Arr::toAssoc((array) $rels);
     $this->joinNestedRels($this->getRepo(), $rels, $this->getRepo()->getTable());
     return $this;
 }
示例#3
0
 /**
  * @return array
  */
 public function getPublicPropertyNames()
 {
     $properties = $this->getProperties(ReflectionProperty::IS_PUBLIC);
     return Arr::invoke($properties, 'getName');
 }
示例#4
0
 /**
  * @dataProvider dataGroupBy
  */
 public function testGroupBy($array, $callback, $preserveKeys, $expected)
 {
     $this->assertSame($expected, Arr::groupBy($array, $callback, $preserveKeys));
 }
示例#5
0
文件: Repo.php 项目: harp-orm/harp
 /**
  * Load all the models for the provided relations. This is the meat of the eager loading
  *
  * @param  Models           $models
  * @param  array            $rels
  * @param  int              $flags
  * @return Repo $this
  */
 public function loadAllRelsFor(Models $models, array $rels, $flags = null)
 {
     $rels = Arr::toAssoc($rels);
     foreach ($rels as $relName => $childRels) {
         $foreign = $this->loadRelFor($models, $relName, $flags);
         if ($childRels) {
             $rel = $this->getRel($relName);
             $rel->getRepo()->loadAllRelsFor($foreign, $childRels, $flags);
         }
     }
     return $this;
 }