[CDBI] Retrieving Columns Other then Essentials

Bill Moseley moseley at hank.org
Sat Mar 18 01:55:34 GMT 2006

On Sat, Mar 18, 2006 at 09:16:27AM +1100, Rick Welykochy wrote:
> It is false economy to niggle about a column here or there: the
> many (hidden) returns trips to the database bog your app down
> far far more than loading a few extra columns that you might
> not use.

I haven't used this in a while, and I'm not sure it's accurate, but
it's suppose to note when CDBI is going back to the database.  I
suspect there's an easier way to do it.

Anyway, in the base class:

sub get {
    my ($self, @columns) = @_;

    # Get the columss that we are requested and not already in the object
    my @fetch_cols = grep {
    } $self->_find_columns(@columns);

    # Find what groups the column(s) is in and the get other columns
    # that are part of that group.
    if ( @fetch_cols ) {

        my @select_cols =
            grep { 
            } $self->__grouper->columns_in(
                # Groups, excluding temp for the columns
                grep { $_ ne 'TEMP' } $self->__grouper->groups_for(@fetch_cols)

        # Now, not all requests are lazy loading, some are due to has_a relationships
        # where only the column has been set.
        my %primary_key = map { $_ => 1 } $self->primary_columns;
        # are any columns other than the primary keys already loaded?

        warn "Lazy Request for [@columns] fetching [@select_cols] from table '", $self->table,"'\n"
            if  grep { !$primary_key{$_} } keys %$self;

    $self->SUPER::get( @columns );

Bill Moseley
moseley at hank.org

More information about the ClassDBI mailing list