Subject: | Calling Essential twice |
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. Could be an issue when subclassing.
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";