Skip to content

Commit

Permalink
NEW Use custom list for eagerloaded relations
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Aug 1, 2023
1 parent 2930308 commit ea68fa6
Show file tree
Hide file tree
Showing 15 changed files with 3,663 additions and 247 deletions.
17 changes: 17 additions & 0 deletions src/ORM/ArrayLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,21 @@ public static function iterateVolatile(array &$list)
}
}
}

/**
* Similar to shuffle, but retains the existing association between the keys and the values.
* Shuffles the array in place.
*/
public static function shuffleAssociative(array &$array): void
{
$shuffledArray = [];
$keys = array_keys($array);
shuffle($keys);

foreach ($keys as $key) {
$shuffledArray[$key] = $array[$key];
}

$array = $shuffledArray;
}
}
19 changes: 14 additions & 5 deletions src/ORM/Connect/MySQLQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,20 @@ public function getIterator(): Traversable
}
yield $data;
}
// Check for the method first since $this->handle is a mixed type
if (method_exists($this->handle, 'data_seek')) {
// Reset so the query can be iterated over again
$this->handle->data_seek(0);
}

// Reset so the query can be iterated over again
$this->rewind();
}
}

/**
* Rewind to the first row
*/
public function rewind(): void
{
// Check for the method first since $this->handle is a mixed type
if (method_exists($this->handle, 'data_seek')) {
$this->handle->data_seek(0);
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/ORM/Connect/MySQLStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,17 @@ public function getIterator(): Traversable
yield $row;
}

// Reset so the query can be iterated over again
$this->rewind();
}

/**
* Rewind to the first row
*/
public function rewind(): void
{
// Check for the method first since $this->statement isn't strongly typed
if (method_exists($this->statement, 'data_seek')) {
// Reset so the query can be iterated over again
$this->statement->data_seek(0);
}
}
Expand Down
Loading

0 comments on commit ea68fa6

Please sign in to comment.