mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-1048: Boolean type issue #1309
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Feb 27, 2011).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user websirnik:
I'm having issues working with Doctrine2 boolean type. My mapping is basic:
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.
@doctrinebot commented on GitHub (Feb 27, 2011):
@doctrinebot commented on GitHub (Mar 4, 2011):
Comment created by @beberlei:
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.
@doctrinebot commented on GitHub (Mar 4, 2011):
Comment created by websirnik:
Sorry don't know how to use your Testsuite.
So basically what I have:
Symfony 2 PR6 standard sandbox with the following config:
Then I have simple entity:
Run the following commands:
And finally I have simple action in the HelloController:
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.
@doctrinebot commented on GitHub (Oct 15, 2011):
Comment created by @beberlei:
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?
@doctrinebot commented on GitHub (Nov 8, 2011):
Comment created by @asm89:
Lowered the priority of this issue until we receive more feedback.
@doctrinebot commented on GitHub (Mar 15, 2012):
Comment created by @asm89:
Closing because we were unable to reproduce and no further feedback was provided.
@doctrinebot commented on GitHub (Mar 15, 2012):
Issue was closed with resolution "Cannot Reproduce"
@doctrinebot commented on GitHub (May 13, 2012):
Comment created by wildlyinaccurate:
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:
Persisting a new Test entity like this works fine.
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:
@doctrinebot commented on GitHub (May 13, 2012):
Comment created by wildlyinaccurate:
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.
@doctrinebot commented on GitHub (May 29, 2012):
Comment created by tobre:
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.
@doctrinebot commented on GitHub (Dec 20, 2012):
Comment created by piotrjura:
Run into same problem here with Doctrine 2.3.x and MySQL 5.5.16 running on Windows 7 with Symfony2. Using query builder:
I have to use literal 'false' or 0.
@doctrinebot commented on GitHub (Apr 5, 2013):
Comment created by cordoval:
@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.
@doctrinebot commented on GitHub (Apr 5, 2013):
Comment created by @ocramius:
Won't reopen without failing test case
@doctrinebot commented on GitHub (Apr 10, 2013):
Comment created by cordoval:
https://github.com/doctrine/doctrine2/pull/647
@doctrinebot commented on GitHub (Apr 12, 2013):
Comment created by @ocramius:
[~cordoval] your test is not related with this issue :\
@doctrinebot commented on GitHub (Feb 28, 2014):
Comment created by kwisatz:
We're experiencing the exact same issue.
We have a model with quite a few boolean properties, such as
{panel}
/****
*
*/
private $is_private;
/****
*
*/
private $deliver;
{panel}
Now, when we set those properties to be booleans and try to persist:
{panel}
$product
->setCode($params['code'])
->setName($params['name'])
->setIsPrivate(false)
[…]
->setDeliver(true);
$em->persist($product);
$em->flush();
{panel}
The result is mysql not executing the prepared statement:
{panel}
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
{panel}
Enabling EchoSQLLogger() shows the query using boolean as well:
{panel}
"START TRANSACTION"
INSERT INTO product (code, name, min_quantity, is_private, deliver, price, long_distance, abroad, vatCategory_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
array(9) {
[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) {
[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"
{panel}
Even passing integers does not work, the only thing working is passing "0" and "1" as strings.
@doctrinebot commented on GitHub (Feb 28, 2014):
Comment created by kwisatz:
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:
Tested this with php5-mysql and php5-mysqlnd, and it doesn't work with either of both.
@gnat42 commented on GitHub (Jan 26, 2022):
I think we hit a bug this may be reporting, I've submitted a PR with a test showing the problem but not a fix in #9430