Can not save "false" in PostgreSQL

I'm trying to save a boolean value into PostreSQL RDBMS. Simplified it looks like following:

// POST => array("field" => "false")
$model->save($this->getPost());

However field remains true. If I manually use boolean value false, then it works ok. PostgreSQL itself knows that "false" string is false

SELECT 'false'::boolean
-- Returns: f

So it seems like Phalcon converts the value into boolean itself somewhere inside before saving, so that "false" string becomes true (which is logical, it's not an empty string).

Does anyone have any hints on how can I avoid such behavior?



7.8k
edited Oct '14

I'm further in debugging. If field is set as "false" string it's not even getting into query:

When "field" => false

LOG:  Ausführen pdo_stmt_00000005: UPDATE "table" SET "field" = $1, "updated_at" = $2 WHERE "id" = $3

when "field" => "false"

LOG:  Ausführen pdo_stmt_00000005: UPDATE "table" SET "updated_at" = $1 WHERE "id" = $2


7.8k

Well, I managed to solve it by creating a custom setter for boolean values:

public function setField($value) {
    if ("false" === $value) $value = false;
    $this->value = $value;
}

However I don't like it. I hope there is a better solution.

Can you use escape character outside the 'false'? ```php POST => array("field" => "\"false\"") ```



7.8k

Thanks for suggestions, I will try it. However what I'm really looking for is how could I set an automatic handler for boolean columns, so that the given value will be converted to boolean.