Skip to content

Commit

Permalink
Changed assign_attribute so that fields with a different inflected na…
Browse files Browse the repository at this point in the history
…me (e.g. capital letters) get casted too

For instance: if you have a field called 'ThisIsADate' it would not become a datetime object.
If the old array_key_exists check fails, a second check is done using the inflected name.
  • Loading branch information
NanneHuiges authored and greut committed Apr 15, 2012
1 parent 32dd63e commit f397a95
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,15 @@ public function __wakeup()
public function assign_attribute($name, $value)
{
$table = static::table();

if (array_key_exists($name,$table->columns) && !is_object($value))
if (array_key_exists($name,$table->columns) && !is_object($value)){
$value = $table->columns[$name]->cast($value,static::connection());

}else{
$col = $table->get_column_by_inflected_name($name);
if (!is_null($col) && !is_object($value)){
$value = $col->cast($value,static::connection());
}
}

// convert php's \DateTime to ours
if ($value instanceof \DateTime)
$value = new DateTime($value->format('Y-m-d H:i:s T'));
Expand Down

0 comments on commit f397a95

Please sign in to comment.