Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Cannot Reproduce
    • Affects Version/s: 2.0
    • Fix Version/s: None
    • Component/s: Mapping Drivers, ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      MySQL, pdo_mysql, Symfony2

      Description

      I'm having issues working with Doctrine2 boolean type. My mapping is basic:

      	/**
      	 * @orm:Column(type="boolean", nullable=false, name="is_deleted")
      	 */
      	protected $isDeleted;
      

      When I'm trying to flush the object with $isDeleted=false (or true), the entity is not being added to the db. However when I set $isDeleted='0' (or '1') everything works fine.

      I saw plenty of examples where people were using true and false, instead of '0' and '1'. But with MySQL it doesn't work. Doctrine maps boolean field as TINYINT(1) in MySQL. And I can see in Symfony2 Profiler the parameter in the query is "false"/"true", so here is data type conflict.

      Doctrine doesn't transform true/false to 1/0 values.

        Issue Links

          Activity

          Hide
          David Raison added a comment -

          Sorry for this second comment, I wasn't aware that I wouldn't be able to edit my first one.
          Here's some data about the system we use:

          • php 5.4.4
          • mysqlserver 5.5.33

          Tested this with php5-mysql and php5-mysqlnd, and it doesn't work with either of both.

          Show
          David Raison added a comment - Sorry for this second comment, I wasn't aware that I wouldn't be able to edit my first one. Here's some data about the system we use: php 5.4.4 mysqlserver 5.5.33 Tested this with php5-mysql and php5-mysqlnd, and it doesn't work with either of both.
          Hide
          David Raison added a comment -

          We're experiencing the exact same issue.
          We have a model with quite a few boolean properties, such as

          /**

          • @var boolean
            *
          • @ORM\Column(name="is_private", type="boolean", nullable=true)
            */
            private $is_private;

          /**

          • @var boolean
            *
          • @ORM\Column(name="deliver", type="boolean")
            */
            private $deliver;

          Now, when we set those properties to be booleans and try to persist:

          $product
          ->setCode($params['code'])
          ->setName($params['name'])
          ->setIsPrivate(false)
          […]
          ->setDeliver(true);

          $em->persist($product);
          $em->flush();

          The result is mysql not executing the prepared statement:

          3358 Query START TRANSACTION
          3358 Prepare INSERT INTO product (code, name, min_quantity, is_private, deliver, price, long_distance, abroad, vatCategory_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
          3358 Close stmt
          3358 Query commit

          Enabling EchoSQLLogger() shows the query using boolean as well:

          "START TRANSACTION"
          INSERT INTO product (code, name, min_quantity, is_private, deliver, price, long_distance, abroad, vatCategory_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
          array(9)

          Unknown macro: { [1]=> string(2) "05" [2]=> string(15) "abcdefg" [3]=> int(400) [4]=> bool(false) [5]=> bool(true) [6]=> int(100) [7]=> bool(false) [8]=> bool(false) [9]=> int(2) }

          array(9)

          Unknown macro: { [1]=> string(6) "string" [2]=> string(6) "string" [3]=> string(7) "integer" [4]=> string(7) "boolean" [5]=> string(7) "boolean" [6]=> string(7) "decimal" [7]=> string(7) "boolean" [8]=> string(7) "boolean" [9]=> string(7) "integer" }

          "COMMIT"

          Even passing integers does not work, the only thing working is passing "0" and "1" as strings.

          Show
          David Raison added a comment - We're experiencing the exact same issue. We have a model with quite a few boolean properties, such as /** @var boolean * @ORM\Column(name="is_private", type="boolean", nullable=true) */ private $is_private; /** @var boolean * @ORM\Column(name="deliver", type="boolean") */ private $deliver; Now, when we set those properties to be booleans and try to persist: $product ->setCode($params ['code'] ) ->setName($params ['name'] ) ->setIsPrivate(false) […] ->setDeliver(true); $em->persist($product); $em->flush(); The result is mysql not executing the prepared statement: 3358 Query START TRANSACTION 3358 Prepare INSERT INTO product (code, name, min_quantity, is_private, deliver, price, long_distance, abroad, vatCategory_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) 3358 Close stmt 3358 Query commit Enabling EchoSQLLogger() shows the query using boolean as well: "START TRANSACTION" INSERT INTO product (code, name, min_quantity, is_private, deliver, price, long_distance, abroad, vatCategory_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) array(9) Unknown macro: { [1]=> string(2) "05" [2]=> string(15) "abcdefg" [3]=> int(400) [4]=> bool(false) [5]=> bool(true) [6]=> int(100) [7]=> bool(false) [8]=> bool(false) [9]=> int(2) } array(9) Unknown macro: { [1]=> string(6) "string" [2]=> string(6) "string" [3]=> string(7) "integer" [4]=> string(7) "boolean" [5]=> string(7) "boolean" [6]=> string(7) "decimal" [7]=> string(7) "boolean" [8]=> string(7) "boolean" [9]=> string(7) "integer" } "COMMIT" Even passing integers does not work, the only thing working is passing "0" and "1" as strings.
          Hide
          Marco Pivetta added a comment -

          Luis Cordova your test is not related with this issue :\

          Show
          Marco Pivetta added a comment - Luis Cordova your test is not related with this issue :\
          Show
          Luis Cordova added a comment - https://github.com/doctrine/doctrine2/pull/647
          Hide
          Marco Pivetta added a comment -

          Won't reopen without failing test case

          Show
          Marco Pivetta added a comment - Won't reopen without failing test case

            People

            • Assignee:
              Benjamin Eberlei
              Reporter:
              Nikita Korotaev
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: