diff --git a/src/LQDN/Handler/CounterpartHandler.php b/src/LQDN/Handler/CounterpartHandler.php index 00cd90b0538dd0948718dd6af99e3c15d85560cb..59d855f4c6e1817b6c04bba4bb9473dc9aa98ed5 100644 --- a/src/LQDN/Handler/CounterpartHandler.php +++ b/src/LQDN/Handler/CounterpartHandler.php @@ -131,8 +131,8 @@ EOF; // Those are the parents ID, grouped by day. $parents = $this->connection->executeQuery( - "select id from contreparties WHERE user_id = :user_id group by user_id, dayofyear(datec) order by field(quoi, 'piplome', 'pibag', 'pishirt', 'hoodie')", - [ 'user_id' => $user_id] + "SELECT id FROM contreparties c JOIN (SELECT MAX(FIELD(quoi, 'piplome', 'pibag', 'pishirt', 'hoodie')) m FROM contreparties GROUP BY user_id, dayofyear(datec)) AS m WHERE FIELD(c.quoi, 'piplome', 'pibag', 'pishirt', 'hoodie') = m.m AND user_id = :user_id", + [ 'user_id' => $user_id ] )->fetchAll(\PDO::FETCH_COLUMN); foreach ($parents as $parent) { diff --git a/tests/functional/Handler/CounterpartHandlerTest.php b/tests/functional/Handler/CounterpartHandlerTest.php index 444b3f25169520ce0d8b697555b6d65903d8eea4..26ceee36fcc3764d6a2b3a40b15f4073c641b4fb 100644 --- a/tests/functional/Handler/CounterpartHandlerTest.php +++ b/tests/functional/Handler/CounterpartHandlerTest.php @@ -15,7 +15,7 @@ class CounterpartHandlerTest extends FunctionalTest { $this->container['command_handler']->handle(new AdminUpdateParentCommand()); $target = $this->container['counterpart_finder']->findById(4); - $this->assertSame((int) $target['parent'], 2); + $this->assertSame((int) $target['parent'], 4); } public function testCounterpartDelete()