Re: Calculation of non-database columns
[prev]
[thread]
[next]
[Date index for 2005/06/02]
On 6/2/05, Uwe Voelker <uwe.voelker@xxx.xx> wrote:
> Hello,
>=20
> I have a table with two dates ('from' and 'to'). I inflate them (with
> has_a) to a DateTime object.
>=20
> Now I want to calculate the timespan between these two DateTime objects
> everytime the record is read from the database. Can I use TEMP columns
> for this? How? (The problem is not the calculation itself, it's the
> Class-DBI context.)
>=20
> Or should I use trigger? But which one? The two DateTime objects need
> already to be inflated.
how about something simple like this:
sub duration {
my $self =3D shift;
return $self->to - $self->from;
}
Put that into your table class, and call it like any other column.=20
The only drawback is that it is calculated evertime it is called, but
it is not an expensive operation so it shouldn't be a problem.
Cheers,
Cees
|
|
Re: Calculation of non-database columns
Cees Hek 23:02 on 02 Jun 2005
|