Re: Calculation of non-database columns
[prev]
[thread]
[next]
[Date index for 2005/06/03]
> Thanks, this solves my problem.
>=20
> But just for curiosity: Is there a way to accomplish this in CDBI? Maybe
> with a TEMP column and has_a? The problem I see there is the missing
> class. Also to and from must already be deflated...
>=20
> __PACKAGE__->has_a(duration =3D> '???',
> deflate =3D> sub { $obj->to - $obj->from },
> );
Actually you can subtract two DateTime objects and it will return you
a DateTime::Duration object. So the function I gave you actually
depends on the objects being inflated to DateTime objects for it to
work.
As for your has_a question, your missing class above would just be
'DateTime::Duration'. But I don't think you can use has_a with a TEMP
column.
Is there a reason that the simple function I provided is not adequate?
It exists in your Class::DBI table class, and it looks and works just
like a Class::DBI column works except that it is readonly (you might
want to improve the function to enforce that). Is it missing a
feature that is needed?
Cheers,
Cees