Pheasant\Relationship::normalizeMap PHP Method

normalizeMap() public static method

Takes either a flat array of relationships or a nested key=>value array and returns it as a nested format
public static normalizeMap ( $array ) : array
return array
    public static function normalizeMap($array)
    {
        $nested = array();
        foreach ((array) $array as $key => $value) {
            if (is_numeric($key)) {
                $nested[$value] = array();
            } else {
                $nested[$key] = $value;
            }
        }
        return $nested;
    }

Usage Example

示例#1
0
 /**
  * Eager load relationships to avoid the N+1 problem
  * @chainable
  */
 public function includes($rels)
 {
     foreach (Relationship::normalizeMap($rels) as $alias => $nested) {
         $this->_includes[$alias] = new Relationships\Includer($this->_query, $this->_schema->relationship($alias), $nested);
     }
     return $this;
 }