public function load($names)
    {
        foreach ((array) $names as $name) {
            // 1. Load relation config
            $parts = explode('.', $name, 2);
            $name = $parts[0];
            $next = isset($parts[1]) ? $parts[1] : null;
            if (isset($this->loadedRelations[$name])) {
                continue;
            }

            /** @var BaseModel $related */
            $related = $this->$name();
            $isColl = $related->isColl();
            $serviceName = $this->getClassServiceName($related);
            $relation = $this->relations[$serviceName];

            // 2. Fetch relation record data
            $ids = $this->getAll($relation['localKey']);
            $ids = array_unique(array_filter($ids));
            if ($ids) {
                $this->relatedValue = $ids;
                $related = $this->$name();
                $this->relatedValue = null;
            } else {
                $related = null;
            }

            // 3. Load relation data
            if (isset($relation['junctionTable'])) {
                $records = $this->loadBelongsToMany($related, $relation, $name);
            } elseif ($isColl) {
                $records = $this->loadHasMany($related, $relation, $name);
            } else {
                $records = $this->loadHasOne($related, $relation, $name);
            }

            // 4. Load nested relations
            if ($next && $records) {
                $records->load($next);
            }

            $this->loadedRelations[$name] = true;
        }

        return $this;
    }
public function load($names)
    {
        foreach ((array) $names as $name) {
            // 1. Load relation config
            $parts = explode('.', $name, 2);
            $name = $parts[0];
            $next = isset($parts[1]) ? $parts[1] : null;
            if (isset($this->loadedRelations[$name])) {
                continue;
            }

            /** @var BaseModel $related */
            $related = $this->$name();
            $isColl = $related->isColl();
            $serviceName = $this->getClassServiceName($related);
            $relation = $this->relations[$serviceName];

            // 2. Fetch relation record data
            $ids = $this->getAll($relation['localKey']);
            $ids = array_unique(array_filter($ids));
            if ($ids) {
                $this->relatedValue = $ids;
                $related = $this->$name();
                $this->relatedValue = null;
            } else {
                $related = null;
            }

            // 3. Load relation data
            if (isset($relation['junctionTable'])) {
                $records = $this->loadBelongsToMany($related, $relation, $name);
            } elseif ($isColl) {
                $records = $this->loadHasMany($related, $relation, $name);
            } else {
                $records = $this->loadHasOne($related, $relation, $name);
            }

            // 4. Load nested relations
            if ($next && $records) {
                $records->load($next);
            }

            $this->loadedRelations[$name] = true;
        }

        return $this;
    }
public function load ( $ names ) { foreach ( ( array ) $ names as $ name ) { // 1. Load relation config $ parts = explode ( '.' , $ name , 2 ) ; $ name = $ parts [ 0 ] ; $ next = isset ( $ parts [ 1 ] ) ? $ parts [ 1 ] : null ; if ( isset ( $ this -> loadedRelations [ $ name ] ) ) { continue ; } /** @var BaseModel $related */ $ related = $ this -> $ name ( ) ; $ isColl = $ related -> isColl ( ) ; $ serviceName = $ this -> getClassServiceName ( $ related ) ; $ relation = $ this -> relations [ $ serviceName ] ; // 2. Fetch relation record data $ ids = $ this -> getAll ( $ relation [ 'localKey' ] ) ; $ ids = array_unique ( array_filter ( $ ids ) ) ; if ( $ ids ) { $ this -> relatedValue = $ ids ; $ related = $ this -> $ name ( ) ; $ this -> relatedValue = null ; } else { $ related = null ; } // 3. Load relation data if ( isset ( $ relation [ 'junctionTable' ] ) ) { $ records = $ this -> loadBelongsToMany ( $ related , $ relation , $ name ) ; } elseif ( $ isColl ) { $ records = $ this -> loadHasMany ( $ related , $ relation , $ name ) ; } else { $ records = $ this -> loadHasOne ( $ related , $ relation , $ name ) ; } // 4. Load nested relations if ( $ next && $ records ) { $ records -> load ( $ next ) ; } $ this -> loadedRelations [ $ name ] = true ; } return $ this ; }
Eager load relations

@param string|array $names
@return $this|$this[]
Eager load relations