[CDBI] Calling columns( Essential ) twice

Christopher H. Laco claco at chrislaco.com
Wed Sep 28 18:34:10 BST 2005


Bill Moseley wrote:
> 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";
> 

I don't think Tony surfs this list much, if at all, so make sure to file 
an RT on the issue. I know he checks those.

This would probably be even more of an issue if a subclass of your class 
wants to call __PACKAGE__->columns to override the base classes 
decisions about what is and isn't essential.

-=Chris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3178 bytes
Desc: S/MIME Cryptographic Signature
Url : http://lists.digitalcraftsmen.net/mailman/private/classdbi/attachments/20050928/daffc42d/smime.bin


More information about the ClassDBI mailing list