[DDC-1048] Boolean type issue Created: 27/Feb/11 Updated: 12/Apr/13 Resolved: 15/Mar/12 |
|
| Status: | Closed |
| Project: | Doctrine 2 - ORM |
| Component/s: | Mapping Drivers, ORM |
| Affects Version/s: | 2.0 |
| Fix Version/s: | None |
| Security Level: | All |
| Type: | Bug | Priority: | Minor |
| Reporter: | Nikita Korotaev | Assignee: | Benjamin Eberlei |
| Resolution: | Cannot Reproduce | Votes: | 0 |
| Labels: | None | ||
| Environment: |
MySQL, pdo_mysql, Symfony2 |
||
| Issue Links: |
|
||||||||
| 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. |
| Comments |
| Comment by Benjamin Eberlei [ 04/Mar/11 ] |
|
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. |
| Comment by Nikita Korotaev [ 04/Mar/11 ] |
|
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 |
| Comment by Benjamin Eberlei [ 15/Oct/11 ] |
|
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? |
| Comment by Alexander [ 08/Nov/11 ] |
|
Lowered the priority of this issue until we receive more feedback. |
| Comment by Alexander [ 15/Mar/12 ] |
|
Closing because we were unable to reproduce and no further feedback was provided. |
| Comment by Joseph Wynn [ 13/May/12 ] |
|
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; |
| Comment by Joseph Wynn [ 13/May/12 ] |
|
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. |
| Comment by Tõnis Tobre [ 29/May/12 ] |
|
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. So perhaps you couldn't reproduce it because you tested it in Linux. You should run the same test on the Windows machine. |
| Comment by Piotr Jura [ 20/Dec/12 ] |
|
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. |
| Comment by Luis Cordova [ 05/Apr/13 ] |
|
@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. |
| Comment by Marco Pivetta [ 05/Apr/13 ] |
|
Won't reopen without failing test case |
| Comment by Luis Cordova [ 10/Apr/13 ] |
| Comment by Marco Pivetta [ 12/Apr/13 ] |
|
Luis Cordova your test is not related with this issue :\ |