[CDBI] Weird things with has_a and lazy population

Dmitry df2 at wm.ru
Wed Nov 16 10:00:48 GMT 2005


I have  following code with 3 classes:

package ClientApp::DB;
use strict;                              
use Class::DBI::FromForm;                
use Class::DBI::AbstractSearch;          
use base qw/Class::DBI::Pg/;             
__PACKAGE__->set_db('Main', '...', { RaiseError => 1, AutoCommit => 1});
1;

package ClientApp::Domain;
use strict;                                                            
use base qw/Catalyst::Base ClientApp:DB/;
__PACKAGE__->set_up_table('my_domains')
__PACKAGE__->has_a(plan => 'ClientApp::Plan');                                                     
1;

package ClientApp::Plan;
use strict;                                                 
use base qw/Catalyst::Base ClientApp::DB/;
__PACKAGE__->set_up_table('my_plans');
1;

So when i do following simple test:

use ClientApp::Domain;
my $domain = ClientApp::Domain->retrieve(1); # row actually exists in database
print $domain->name;
print $domain->plan;

then it just prints empty strings

Ok, i reading about lazy population and doing the following:

Adding this string to ClientApp::Domain
__PACKAGE__->columns(Essential => qw/name plan/);
and to ClientApp::Plan
__PACKAGE__->columns(Essential => qw/nick/);

result:
print $domain->name; # prints test.com
print $domain->plan; # prints 10

yes thats fine, but:
print $domain->plan->nick; # STILL EMPTY STRING!!

and when i do such way:
use ClientApp::Plan;
my $plan = ClientApp::Plan->retrieve(10);
print $plan->nick; # yes, it prints "good plan" as expected

My curiousity here about "has_a", why Essential thing didn't worked with
it ???
Thanks for help.

PS: Class::DBI version 0.96

--





More information about the ClassDBI mailing list