[CDBI] Calling columns( Essential ) twice

[prev] [thread] [next] [Date index for 2005/09/28]

From: Bill Moseley
Subject: [CDBI] Calling columns( Essential ) twice
Date: 17:06 on 28 Sep 2005
Minor time killer.

I happened to be calling Essential twice on a class.  When I did this
LAZY POPULATION was not working on columns that were no longer in
Essential.  So, don't call Essential twice, I suppose.


    DB::Person->columns( Essential => qw/ id first_name last_name content / );
    DB::Person->columns( Essential => qw/ id first_name last_name  / );

    my $item = DB::Person->retrieve( 1 );

    print $item->content ? "content found\n" : "sorry, out of luck\n";

Results in:

    $ perl one_table.pl 
    sorry, out of luck

when there is indeed content.  CDBI isn't going back to the DB.

Comment out either one (or both) of the Essential calls and it works fine.

Here's a demo on CDBI 3.0.8:


package DB;
use base 'Class::DBI::Sweet';
DB->connection('dbi:mysql:test', '', '');
#DB->connection('dbi:Pg:dbname=test2', '', '');


package DB::Person;
use base 'DB';
__PACKAGE__->table('person');
__PACKAGE__->columns(All => qw/id first_name last_name role content/);

package main;
use strict;
use warnings;
use Template;

DB->db_Main->do("DROP TABLE $_") for qw/ person /;


DB->db_Main->do(<<"");
    CREATE TABLE person (
        id          integer PRIMARY KEY,
        role        integer,
        first_name  text,
        last_name   text,
        content text
    );


DB::Person->create( {
    id          => 1,
    role        => 3,
    first_name  => 'Joe',
    last_name   => 'Blow',
    content     => 'This is some content about Joe',
});


DB::Person->columns( Essential => qw/ id first_name last_name content / );
DB::Person->columns( Essential => qw/ id first_name last_name  / );

my $item = DB::Person->retrieve( 1 );

print $item->content ? "content found\n" : "sorry, out of luck\n";






        -- 
        Bill Moseley
moseley@xxxx.xxx


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

[CDBI] Calling columns( Essential ) twice
Bill Moseley 17:06 on 28 Sep 2005

Re: [CDBI] Calling columns( Essential ) twice
Christopher H. Laco 17:34 on 28 Sep 2005

Generated at 15:06 on 02 Oct 2005 by mariachi v0.52