↓ Archives ↓

Two patches for Lithium (li3)

First, added method _toBoolean to Lithium\data\source\database\adapter\MySql:

    protected function _toBoolean($value) {
        return (int) parent::_toBoolean($value);
    }

Now Lithium treat tinyint(1) in MySQL as boolean type, but when you insert/update with a field has been defined as tinyint(1), Lithium will try insert boolean type, then an SQL error will throws.

The second patch is for Lithium\data\source\Database. Try this:

class User extends Lithium\data\Model {}

$user = User::create();
$user->name = 'Leechael';
$user->email = 'blah@blah.blah';
$user->blah = 'Field that NOT exists in schema';
$user->save();

Than you will got an SQL error, said unknown column `blah`. The solution is add a few lines in method Database::create() and Database::update(). First one, go to line 190:

while (list($field, $value) = each($data['fields'])) { // This line is what we looking for!
    // Insert following block!
    if (!isset($schema[$field])) {
        continue;
    }
// other codes ....

Second, go to line line 274 (after previous patched):

while (list($field, $value) = each($data['fields'])) { // You looking for this!
    if (!isset($schema[$field])) {
        continue;
    }
// other codes ....

Done.

No Comment

Leave a Reply

Sorry, comments are closed.