示例#1
0
 /**
  * Returns a nested tree representation of `'embed'` option.
  *
  * @return array The corresponding nested tree representation.
  */
 public function treeify($embed)
 {
     if (!$embed) {
         return [];
     }
     if ($embed === true) {
         $embed = $this->relations();
     }
     $embed = Set::expand(array_fill_keys(array_keys(Set::normalize((array) $embed)), null));
     $result = [];
     foreach ($embed as $relName => $value) {
         if (!isset($this->_relations[$relName])) {
             continue;
         }
         if ($this->_relations[$relName]['relation'] === 'hasManyThrough') {
             $rel = $this->relation($relName);
             $result[$rel->through()] = [$rel->using() => $value];
         }
         $result[$relName] = $value;
     }
     return $result;
 }
示例#2
0
 /**
  * Sets the relations to retrieve.
  *
  * @param  array  $embed The relations to load with the query.
  * @return object        Returns `$this`.
  */
 public function embed($embed = null, $conditions = [])
 {
     if (!$embed) {
         return $this->_embed;
     }
     if (!is_array($embed)) {
         $embed = [$embed => $conditions];
     }
     $embed = Set::normalize($embed);
     $this->_embed = Set::merge($this->_embed, $embed);
     return $this;
 }