vlucas / Spot

[DEPRECATED - use v2] Simple DataMapper ORM for PHP 5.3+
75 stars 14 forks source link

Re-writing the Type system to support dump and load for persistence. #43

Closed pnomolos closed 11 years ago

pnomolos commented 11 years ago

Also added a 'Serialized' type to test the new changes.

pnomolos commented 11 years ago

One thing that I'm curious about is lines 796-808 of PDO/Abstract.php:

// Handle binding depending on type
if(is_object($value)) {
    if($value instanceof \DateTime) {
        // @todo Need to take into account column type for date formatting
        $bindValue = (string) $value->format($this->dateTimeFormat());
    } else {
        $bindValue = (string) $value; // Attempt cast of object to string (calls object's __toString method)
    }
} elseif(is_bool($value)) {
    $bindValue = (int) $value; // Cast boolean to integer (false = 0, true = 1)
} elseif(!is_array($value)) {
    $bindValue = $value;
}

These are no longer used for persisting values (well, they shouldn't be - I guess I haven't fully tested this yet) but are still used in conditions. Should we change how conditions work so that the type of the field they are comparing to is checked and they are persisted as a value would be? This would leave the behaviour intact (so you could do array('post_date >' => new \DateTime()) still) and would prevent us casting in two places.