Re: Calculation of non-database columns

[prev] [thread] [next] [Date index for 2005/06/03]

From: Cees Hek
Subject: Re: Calculation of non-database columns
Date: 15:46 on 03 Jun 2005
> 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

Calculation of non-database columns
Uwe Voelker 21:21 on 02 Jun 2005

Re: Calculation of non-database columns
Cees Hek 23:02 on 02 Jun 2005

Re: Calculation of non-database columns
Uwe Voelker 09:57 on 03 Jun 2005

Re: Calculation of non-database columns
Cees Hek 15:46 on 03 Jun 2005

Re: Calculation of non-database columns
Uwe Voelker 11:56 on 04 Jun 2005

Generated at 16:36 on 28 Jul 2005 by mariachi v0.52