Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Boolean value #9

Open
ElGigi opened this issue Feb 12, 2019 · 2 comments
Open

[BUG] Boolean value #9

ElGigi opened this issue Feb 12, 2019 · 2 comments

Comments

@ElGigi
Copy link
Contributor

ElGigi commented Feb 12, 2019

Hi,

In MySQL the boolean value is similar to TINYINT (0: false / 1: true).

In my Domain class, i give in constructor parameters the bool type value, it's work fine when i select a domain. The integer is convert to boolean.

But when i persist the Domain class:

  1. The value taken and given to the mapper is boolean value
  2. The Mapper found that the value is different (boolean <> int)
  3. The ORM execute the UPDATE
  4. The ORM throw an exception because PDO return no updated entry (because boolean converted to integer)

Ronan

@pmjones
Copy link
Contributor

pmjones commented Feb 12, 2019

Yes, I have run into this myself elsewhere. The solution I used was to add a TableEvent::beforeUpdate() to cast the value to integer, a la:

function beforeUpdate($table, $row)
{
    $row->foo = (int) $row->foo;
}

(That happens before the array diff gets calculated, so the int <=> int comparison works correctly.)

It was a little more involved than that, as I looped through the $table column definitions and cast them automatically if they were TINYINT, but the principle is the same.

@pmjones
Copy link
Contributor

pmjones commented Feb 12, 2019

Perhaps the thing to do would be, on the way back to the Record, for the Handlers to cast the domain value to the same type as the original Record value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants