Skip to content

Instantly share code, notes, and snippets.

@beezee
Created October 4, 2012 03:20
Show Gist options
  • Save beezee/3831274 to your computer and use it in GitHub Desktop.
Save beezee/3831274 to your computer and use it in GitHub Desktop.
Mass assignment + custom setter which modifies value type
Class Task extends ActiveRecord\Model
{
public static $table = 'tasks';
public function set_history($history)
{
$this->assign_attribute('history', serialize($history));
}
public function get_history()
{
return unserialize($this->read_attribute('history'));
}
}
$task = new Task(array('history' => array('created' => '12_20_2011')));
$task->history === array('created' => '12_20_2011'); // this should work, but it's false
$task->history === 'Array'; // unfortunately this is true due to model property casting done before custom setter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment