Wrong orderBy when comparing integers
MattKetmo opened this issue · 3 comments
MattKetmo commented
Hello,
I just found that the order in inversed when using orderBy
with a field which contains an integer.
Example:
<?php
require __DIR__.'/vendor/autoload.php';
use JamesMoss\Flywheel\Config;
use JamesMoss\Flywheel\Document;
use JamesMoss\Flywheel\Repository;
$rootDir = sys_get_temp_dir().'/poc_flywheel_orderBy_'.rand();
$config = new Config($rootDir);
$repo = new Repository('posts', $config);
$posts = [
new Document(['title' => 'AAA', 'number' => 1]),
new Document(['title' => 'BBB', 'number' => 2]),
new Document(['title' => 'CCC', 'number' => 3]),
];
foreach ($posts as $post) {
$repo->store($post);
}
echo "Order by title ASC:\n";
$posts = $repo->query()->orderBy('title ASC')->execute();
foreach ($posts as $post) {
echo "{$post->title} - {$post->number}\n";
}
echo PHP_EOL;
echo "Order by number ASC:\n";
$posts = $repo->query()->orderBy('number ASC')->execute();
foreach ($posts as $post) {
echo "{$post->title} - {$post->number}\n";
}
It displays:
Order by title ASC:
AAA - 1
BBB - 2
CCC - 3
Order by number ASC:
CCC - 3
BBB - 2
AAA - 1
The two list should be the same but the second one is inversed.
prolic commented
👍
MattKetmo commented
Awesome, thanks.
Do you plan a new release soon?