src/mako/database/midgard/relations/ManyToMany.php
public function eagerLoad(array &$results, string $relation, ?Closure $criteria, array $includes): void
	{
		$this->model->setIncludes($includes);

		$grouped = [];

		if($criteria !== null)
		{
			$criteria($this);
		}

		$foreignKey = $this->getForeignKey();

		foreach($this->eagerLoadChunked($this->keys($results)) as $related)
		{
			$grouped[$related->getRawColumnValue($foreignKey)][] = $related;

			unset($related->$foreignKey); // Unset as its not a part of the record
		}

		foreach($results as $result)
		{
			$result->setRelated($relation, $this->createResultSet($grouped[$result->getPrimaryKeyValue()] ?? []));
		}
	}
public function eagerLoad(array &$results, string $relation, ?Closure $criteria, array $includes): void
	{
		$this->model->setIncludes($includes);

		$grouped = [];

		if($criteria !== null)
		{
			$criteria($this);
		}

		$foreignKey = $this->getForeignKey();

		foreach($this->eagerLoadChunked($this->keys($results)) as $related)
		{
			$grouped[$related->getRawColumnValue($foreignKey)][] = $related;

			unset($related->$foreignKey); // Unset as its not a part of the record
		}

		foreach($results as $result)
		{
			$result->setRelated($relation, $this->createResultSet($grouped[$result->getPrimaryKeyValue()] ?? []));
		}
	}
public function eagerLoad ( array & $ results , string $ relation , ? Closure $ criteria , array $ includes ) : void { $ this -> model -> setIncludes ( $ includes ) ; $ grouped = [ ] ; if ( $ criteria !== null ) { $ criteria ( $ this ) ; } $ foreignKey = $ this -> getForeignKey ( ) ; foreach ( $ this -> eagerLoadChunked ( $ this -> keys ( $ results ) ) as $ related ) { $ grouped [ $ related -> getRawColumnValue ( $ foreignKey ) ] [ ] = $ related ; unset ( $ related -> $ foreignKey ) ; // Unset as its not a part of the record } foreach ( $ results as $ result ) { $ result -> setRelated ( $ relation , $ this -> createResultSet ( $ grouped [ $ result -> getPrimaryKeyValue ( ) ] ?? [ ] ) ) ; } }
Eager loads related records and matches them with their parent records.

@param array         &$results Parent records
@param string        $relation Relation name
@param \Closure|null $criteria Relation criteria
@param array         $includes Includes passed from the parent record
Eager loads related records and matches them with their parent records .