Doctrine 1
  1. Doctrine 1
  2. DC-852

CLONE -Fix returned type value : SQL integers to PHP integers when getting a value from the database.

    Details

      Description

      Hi Jon,

      I have a request for you to improve Doctrine. When declaring a column as an integer, it seems that Doctrine returns a string when getting the value of that column. For example, if I have a "status" column, which can take 0, 1 or 2 as its value, Doctrine will return these values as string, which is not really logical and returning the good PHP type is the goal of an ORM. I'm fond of the triple equal symbol to test a value and I did not understand why this did not work at start :

      // in my myModel class
      class myModel extends Doctrine_Record
      {
      const STATUS_VALIDATED = 1;

      public function isValidated()

      { return self::STATUS_VALIDATED === $this->getStatus(); }

      }

      That's why getStatus() gives me a string instead of an integer, whereas the column is declared as an integer in my schema. I'm forced to cast myself the returned value of getStatus() in my model.

        Activity

        Hide
        Enrico Stahn added a comment -
        Show
        Enrico Stahn added a comment - Proposal for a solution: http://github.com/estahn/doctrine1/compare/master...DC-852
        Hide
        Jonathan H. Wage added a comment -

        So if you enable this attribute you live with the fact that casting a string to an integer that is longer than php max integer will give weird results?

        Show
        Jonathan H. Wage added a comment - So if you enable this attribute you live with the fact that casting a string to an integer that is longer than php max integer will give weird results?
        Hide
        Enrico Stahn added a comment -

        i'm far from happy with this solution. if an integer that is greater than php max int gets casted it will be casted into a value of type double. if you enable that attribute only values that could successfully casted into an integer will be casted otherwise an exception will be thrown.

        Show
        Enrico Stahn added a comment - i'm far from happy with this solution. if an integer that is greater than php max int gets casted it will be casted into a value of type double. if you enable that attribute only values that could successfully casted into an integer will be casted otherwise an exception will be thrown.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Enrico Stahn
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: