-1

i'm not used to develop with Symfony, I retrieved an old project which has to be improved.

Here is my problem : In back-end, I have clients with several appointments (HasMany), or none. In front-end, from my rest api call, I receive the clients with appointments. No problem. But I would like to receive only appointments of today ("start" attribute in appointment model).

How can I apply that directly in back-end ? I know there are a lot of way to use symfony with Doctrine and annotations ... but can't find the right answer.

Thanks

Jean-louis Gouwy
  • 182
  • 3
  • 10

2 Answers2

1

Erm.. you select everything from your table with the today day nothing too fancy. :-) ex:

"SELECT * FROM appointments WHERE date >= CURDATE()"

Of course this would need to be translated to doctrine but you have the above example to start.

Bogdan
  • 693
  • 7
  • 26
  • Thanks, but I know how to do in sql .. but I would like to reuse what I have in the project, I have any unit test, I have a function who send me already the data, I just want to know if there is a simple way to filter easily from doctrine and annotation. My function does $this->repository->findBy($criteria, $orderBy, $limit, $offset). In Symfony, i know we can do a lot of thing easily and "magically" adding a simple annotation for example ... i'm not very clear ^^ – Jean-louis Gouwy Aug 07 '18 at 08:41
  • 1
    I reckon you might need to define something in your `EntityRepository`, you can't do comparaison ">" in `findBy` – Gregoire Ducharme Aug 07 '18 at 09:21
  • yes he needs a custom method based on his requirements that will do the job. a method should have only a single purpose. – Bogdan Aug 07 '18 at 09:54
  • I publish the request I don't success to apply in my repository @GregoireDucharme – Jean-louis Gouwy Aug 07 '18 at 12:43
0

here the request I don't success to apply in my repository with query builder:

SELECT * 
FROM ikc_client
LEFT JOIN (
  SELECT *
  FROM ikc_appointment
  WHERE ikc_appointment.start > '2018-08-07 00:00:00'
  AND ikc_appointment.end < '2018-08-07 23:59:59'
) appointment ON appointment.client_id = ikc_client.id
Jean-louis Gouwy
  • 182
  • 3
  • 10