Ejemplo n.º 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);
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 3
0
 /**
  * @return array
  */
 public function getPublicPropertyNames()
 {
     $properties = $this->getProperties(ReflectionProperty::IS_PUBLIC);
     return Arr::invoke($properties, 'getName');
 }
Ejemplo n.º 4
0
 /**
  * @dataProvider dataGroupBy
  */
 public function testGroupBy($array, $callback, $preserveKeys, $expected)
 {
     $this->assertSame($expected, Arr::groupBy($array, $callback, $preserveKeys));
 }
Ejemplo n.º 5
0
 /**
  * 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;
 }