Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1282

getDateAddDaysExpression() casts $days to integer preventing column based add expressions.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.1.1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      MySQL

      Description

      Take the following:

      $qb = $this->createQueryBuilder('a');
      $qb->select('partial a.

      {dsid,rid,activeStartDate}');
      $qb->leftJoin('a.clinic', 'c');
      $qb->leftJoin('a.patient', 'p');
      $qb->where('c.autoAppointmentReminders = 1');
      $qb->andWhere('a.enabled = 1');
      $qb->andWhere(
      $qb->expr()->eq(
      'a.activeStartDate',
      "DATE_ADD(CURRENT_DATE(), c.appointmentRemindersDaysInAdvance, 'day')"));

      Which generates the DQL: SELECT partial a.{dsid,rid,activeStartDate}

      FROM VetLogic\Entity\Appointment a LEFT JOIN a.clinic c LEFT JOIN a.patient p WHERE c.autoAppointmentReminders = 1 AND a.enabled = 1 AND a.activeStartDate = DATE_ADD(CURRENT_DATE(), c.appointmentRemindersDaysInAdvance, 'day')

      And SQL: SELECT a0_.rid AS rid0, a0_.dsid AS dsid1, a0_.activeStartDate AS activeStartDate2, a0_.dsid AS dsid3, a0_.dsid AS dsid4, a0_.clinicRid AS clinicRid5, a0_.dsid AS dsid6, a0_.patientRid AS patientRid7, a0_.dsid AS dsid8, a0_.rid AS rid9 FROM appointment a0_ LEFT JOIN clinic c1_ ON a0_.dsid = c1_.dsid AND a0_.clinicRid = c1_.rid LEFT JOIN patient p2_ ON a0_.dsid = p2_.dsid AND a0_.patientRid = p2_.rid WHERE c1_.autoAppointmentReminders = 1 AND a0_.enabled = 1 AND a0_.activeStartDate = DATE_ADD(CURRENT_DATE, INTERVAL0 DAY)

      The DATE_ADD(CURRENT_DATE, INTERVAL0 DAY) is generated incorrectly because getDateAddDaysExpression($date, $days) casts $days to an integer.

      The fix is simply to remove (int) from return 'DATE_ADD(' . $date . ', INTERVAL ' . (int)$days . ' DAY)';

      Note: I only checked the MySQL platform so I'm not sure if other platforms are affected.

        Activity

        Hide
        Benjamin Eberlei added a comment -

        Fixed

        Show
        Benjamin Eberlei added a comment - Fixed

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Kyle Spraggs
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: