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

          Nikita Korotaev created issue -
          Nikita Korotaev made changes -
          Field Original Value New Value
          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.
          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.
          Hide
          Benjamin Eberlei added a comment -

          Boolean works fine for me with MySQL since forever, i cannot reproduce this. Can you come up with a reproducable test-case in our Testsuite? Otherwise odds are pretty slim to fix this, as i need to see whats happening.

          Show
          Benjamin Eberlei added a comment - Boolean works fine for me with MySQL since forever, i cannot reproduce this. Can you come up with a reproducable test-case in our Testsuite? Otherwise odds are pretty slim to fix this, as i need to see whats happening.
          Hide
          Nikita Korotaev added a comment - - edited

          Sorry don't know how to use your Testsuite.

          So basically what I have:

          Symfony 2 PR6 standard sandbox with the following config:

          doctrine:
             dbal:
                 dbname:   shop
                 user:     root
                 password: ~
                 logging:  %kernel.debug%
             orm:
                 auto_generate_proxy_classes: %kernel.debug%
                 mappings:
                     HelloBundle: ~
          

          Then I have simple entity:

          <?php
          
          namespace Sensio\HelloBundle\Entity;
          
          /**
           * @orm:Entity()
           * @orm:Table(name="product")
           */
          class Product
          {
              /**
               * @orm:Id
               * @orm:GeneratedValue
               * @orm:Column(type="integer")
               */
              private $id;
          
              /** @orm:Column(type="text", nullable=false) */
              private $name;
          
              
              /** @orm:Column(type="boolean") */
              private $inStock;
              
              public function getId()
              {
                  return $this->id;
              }
          
              public function setName($name)
              {
                  $this->name = $name;
              }
          
              public function getName()
              {
                  return $this->name;
              }
          
              public function setInStock($inStock)
              {
                  $this->inStock = $inStock;
              }
          
              public function getInStock()
              {
                  return $this->inStock;
              }
          }
          

          Run the following commands:

          php app/console doctrine:database:create
          php app/console doctrine:schema:create
          

          And finally I have simple action in the HelloController:

          <?php
          
          namespace Sensio\HelloBundle\Controller;
          
          use Sensio\HelloBundle\Entity\Product;
          use Symfony\Bundle\FrameworkBundle\Controller\Controller;
          
          class HelloController extends Controller
          {
              public function indexAction($name)
              {
                   $product = new Product();
                   $product->setName($name);
                   $product->setInStock(true);
          		
                   $em = $this->get('doctrine.orm.default_entity_manager');
                   $em->persist($product);
                   $em->flush();
          
                   return $this->render('HelloBundle:Hello:index.html.twig', array('name' => $name));
          
              }
          }
          

          Go to the http://localhost/web/app_dev.php/hello/Product1

          When I set 'true' for inStock attribute, and then flush object to the DB, it doesn't create a row. However when I write $product->setInStock('1') - that's works and the row appears in the DB. And $product->setInStock(1) that's doen't work again. That's a very strange behaviour, and I couldn't explain it anyhow.

          Show
          Nikita Korotaev added a comment - - edited Sorry don't know how to use your Testsuite. So basically what I have: Symfony 2 PR6 standard sandbox with the following config: doctrine: dbal: dbname: shop user: root password: ~ logging: %kernel.debug% orm: auto_generate_proxy_classes: %kernel.debug% mappings: HelloBundle: ~ Then I have simple entity: <?php namespace Sensio\HelloBundle\Entity; /** * @orm:Entity() * @orm:Table(name= "product" ) */ class Product { /** * @orm:Id * @orm:GeneratedValue * @orm:Column(type= "integer" ) */ private $id; /** @orm:Column(type= "text" , nullable= false ) */ private $name; /** @orm:Column(type= " boolean " ) */ private $inStock; public function getId() { return $ this ->id; } public function setName($name) { $ this ->name = $name; } public function getName() { return $ this ->name; } public function setInStock($inStock) { $ this ->inStock = $inStock; } public function getInStock() { return $ this ->inStock; } } Run the following commands: php app/console doctrine:database:create php app/console doctrine:schema:create And finally I have simple action in the HelloController: <?php namespace Sensio\HelloBundle\Controller; use Sensio\HelloBundle\Entity\Product; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class HelloController extends Controller { public function indexAction($name) { $product = new Product(); $product->setName($name); $product->setInStock( true ); $em = $ this ->get('doctrine.orm.default_entity_manager'); $em->persist($product); $em->flush(); return $ this ->render('HelloBundle:Hello:index.html.twig', array('name' => $name)); } } Go to the http://localhost/web/app_dev.php/hello/Product1 — When I set 'true' for inStock attribute, and then flush object to the DB, it doesn't create a row. However when I write $product->setInStock('1') - that's works and the row appears in the DB. And $product->setInStock(1) that's doen't work again. That's a very strange behaviour, and I couldn't explain it anyhow.
          Benjamin Eberlei made changes -
          Link This issue relates to DDC-1394 [ DDC-1394 ]
          Benjamin Eberlei made changes -
          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.
          I'm having issues working with Doctrine2 boolean type. My mapping is basic:

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

          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.
          Hide
          Benjamin Eberlei added a comment -

          This is pretty old. Do you still use boolean types and does it work? The code suggests you maybe used Doctrine 2.0.x back then, does this work with Doctrine 2.1.x for you?

          Show
          Benjamin Eberlei added a comment - This is pretty old. Do you still use boolean types and does it work? The code suggests you maybe used Doctrine 2.0.x back then, does this work with Doctrine 2.1.x for you?
          Hide
          Alexander added a comment -

          Lowered the priority of this issue until we receive more feedback.

          Show
          Alexander added a comment - Lowered the priority of this issue until we receive more feedback.
          Alexander made changes -
          Priority Major [ 3 ] Minor [ 4 ]
          Hide
          Alexander added a comment -

          Closing because we were unable to reproduce and no further feedback was provided.

          Show
          Alexander added a comment - Closing because we were unable to reproduce and no further feedback was provided.
          Alexander made changes -
          Status Open [ 1 ] Closed [ 6 ]
          Resolution Cannot Reproduce [ 5 ]
          Hide
          Joseph Wynn added a comment -

          Hi guys, I was able to reproduce similar behaviour. Simply adding a boolean column to an entity prevents Doctrine from persisting new entities to the database. I am using a freshly-checked-out 2.2.2 with the Laravel PHP framework. Boolean columns have worked for me previously and I wondered whether Laravel's autoloaders were interfering with Doctrine somehow (just a stab in the dark).

          Here is my Test entity:

          <?php
          
          namespace Entity;
          
          /**
           * @Entity
           * @Table(name="test_entry")
           */
          class Test
          {
          
                  /**
                   * @Id
                   * @Column(type="integer", nullable=false)
                   * @GeneratedValue(strategy="AUTO")
                   */
                  protected $id;
          
                  /**
                   * @Column(type="string", length=40, nullable=false)
                   */
                  protected $string_col;
          
                  public function getId()
                  {
                          return $this->id;
                  }
          
                  public function setStringCol($string_col)
                  {
                          $this->string_col = $string_col;
                  }
          
                  public function getStringCol()
                  {
                          return $this->string_col;
                  }
          
          }
          

          Persisting a new Test entity like this works fine.

          $test = new \Entity\Test;
          $test->setStringCol('String value');
          $em->persist($test);
          $em->flush();
          

          However, if I add a boolean column to the entity, the persist/flush operations seem to fail silently and the record is not inserted. The boolean column looks like this:

          /**
           * @Column(type="boolean", nullable=false)
           */
          protected $bool_col = false;
          
          Show
          Joseph Wynn added a comment - Hi guys, I was able to reproduce similar behaviour. Simply adding a boolean column to an entity prevents Doctrine from persisting new entities to the database. I am using a freshly-checked-out 2.2.2 with the Laravel PHP framework. Boolean columns have worked for me previously and I wondered whether Laravel's autoloaders were interfering with Doctrine somehow (just a stab in the dark). Here is my Test entity: <?php namespace Entity; /** * @Entity * @Table(name= "test_entry" ) */ class Test { /** * @Id * @Column(type= "integer" , nullable= false ) * @GeneratedValue(strategy= "AUTO" ) */ protected $id; /** * @Column(type= "string" , length=40, nullable= false ) */ protected $string_col; public function getId() { return $ this ->id; } public function setStringCol($string_col) { $ this ->string_col = $string_col; } public function getStringCol() { return $ this ->string_col; } } Persisting a new Test entity like this works fine. $test = new \Entity\Test; $test->setStringCol(' String value'); $em->persist($test); $em->flush(); However, if I add a boolean column to the entity, the persist/flush operations seem to fail silently and the record is not inserted. The boolean column looks like this: /** * @Column(type= " boolean " , nullable= false ) */ protected $bool_col = false ;
          Hide
          Joseph Wynn added a comment -

          Sorry, forgot to say that explicitly setting the value of bool_col doesn't make a difference. I have also tried setting the value to (int) 1 or 0, with the same results.

          Show
          Joseph Wynn added a comment - Sorry, forgot to say that explicitly setting the value of bool_col doesn't make a difference. I have also tried setting the value to (int) 1 or 0, with the same results.
          Hide
          Tõnis Tobre added a comment -

          My development environment is Ubuntu Linux, these boolean types is working well. After new developer put project up on his Windows 7 WAMP machine exactly the same problem happened.
          Firstly thought that MySQL is acting differently, but no, we connected MySQL to Linux server, still same problem. The solution was to replace boolean types to integers.

          So perhaps you couldn't reproduce it because you tested it in Linux. You should run the same test on the Windows machine.

          Show
          Tõnis Tobre added a comment - My development environment is Ubuntu Linux, these boolean types is working well. After new developer put project up on his Windows 7 WAMP machine exactly the same problem happened. Firstly thought that MySQL is acting differently, but no, we connected MySQL to Linux server, still same problem. The solution was to replace boolean types to integers. So perhaps you couldn't reproduce it because you tested it in Linux. You should run the same test on the Windows machine.
          Benjamin Eberlei made changes -
          Workflow jira [ 12432 ] jira-feedback [ 15667 ]
          Benjamin Eberlei made changes -
          Workflow jira-feedback [ 15667 ] jira-feedback2 [ 17531 ]
          Benjamin Eberlei made changes -
          Workflow jira-feedback2 [ 17531 ] jira-feedback3 [ 19788 ]
          Hide
          Piotr Jura added a comment -

          Run into same problem here with Doctrine 2.3.x and MySQL 5.5.16 running on Windows 7 with Symfony2. Using query builder:

          Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
          ->where($qb->expr()->eq('c.private', 'false'))
          

          I have to use literal 'false' or 0.

          Show
          Piotr Jura added a comment - Run into same problem here with Doctrine 2.3.x and MySQL 5.5.16 running on Windows 7 with Symfony2. Using query builder: Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml ->where($qb->expr()->eq('c. private ', ' false ')) I have to use literal 'false' or 0.
          Hide
          Luis Cordova added a comment -

          @beberlei @ocramius this should be reopened it is a present bug on 2.3+, i had the same problem rolled back and it works again.

          Show
          Luis Cordova added a comment - @beberlei @ocramius this should be reopened it is a present bug on 2.3+, i had the same problem rolled back and it works again.
          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
          Show
          Luis Cordova added a comment - https://github.com/doctrine/doctrine2/pull/647
          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 :\
          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
          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.

          This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

          • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-1048, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

            People

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

              Dates

              • Created:
                Updated:
                Resolved: