[CDBI] Delay Inflate

[prev] [thread] [next] [Date index for 2006/01/07]

From: Bill Moseley
Subject: [CDBI] Delay Inflate
Date: 16:35 on 07 Jan 2006
I have a column in Essential that inflates to a DataTime object.  I
want to set the timezone on the object, and (for the sake of this
discussion) fetching the timezone requires two more database reads.

It seems CDBI inflates columns when they are first loaded from the
database, not the first time the column is fetched.  So the inflate
code (including those two extra selects) is run even if the column is
not read by the application.

I'd like the inflation to only happen when the column is accessed.
I don't suppose there's any way to do that in CDBI short of removing
the column from Essential, right?


Only other way I can think of is to override the column in my class.
This seem reasonable?


    __PACKAGE__->columns( TEMP => 'time_zone_set' );
    sub my_time_column {
        my ( $item, $dt ) = @_;
        return $item->set('my_time_column', $dt ) if defined $dt;

        $dt = $item->get('my_time_column');
        return $dt if $item->time_zone_set;

        warn "setting time zone\n";
        $dt->set_time_zone( $item->location->time_zone->name );
        $item->set('my_time_column', $dt );
        $item->time_zone_set(1);
        return $dt;

    }

And then hope I don't use $item->get('my_time_column') elsewhere.


        -- 
        Bill Moseley
moseley@xxxx.xxx


_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

[CDBI] Delay Inflate
Bill Moseley 16:35 on 07 Jan 2006

Re: [CDBI] Delay Inflate
Bill Moseley 17:52 on 07 Jan 2006

Generated at 01:21 on 10 Jan 2006 by mariachi v0.52