class TimeRecord extends Voltron_Model
{
protected $table = 'time_record';
protected $fields = array(
'id' => Type::Primary,
'created' => Type::Timestamp,
'created_hour' => Type::Calculated('created')->asDateTime->formatAs('H'));
}
The magic lies with in the created_hour type definition which can also be written as Type::Calculated(I()->created->asDateTime->formatAs('H')).
Because of the oo and fluent nature of Voltron the majority of calculated fields can be defined this way rather than requiring an actual method definition in the record class.
No comments:
Post a Comment