jdtoronto has asked for the wisdom of the Perl Monks concerning the following question:
For some reason my foreign key related values are not being inflated when I retrieve them using Class::DBI.
I have two tables. One called as_dow which has this structure:
and the second, pr_businesshours which looks like this:Field Type Null Key Default Extra -------- ----------- ------- ------ ---------- -------- id int(11) PRI 0 int_dow varchar(50)
The values for int_dow in pr_businesshours are 0..6 corresponding to the days of the week. Likewise in as_dow the keys (id) are 0..6 with the corresponding abbreviated text versions of the days stored in int_dow.Field Type Null Key Default Extra + ------------ ------------- ------- ------ ---------- ----------- +--- interval_id int(11) PRI (null) auto_increm +ent provider_id int(11) 0 + personell_id int(11) 0 + int_type int(11) 0 + int_dow varchar(50) + int_start time 00:00:00 + int_end time 00:00:00 + int_int decimal(10,0) 00
In my sub-classing of Class::DBI I did this:
But when I search for the records, then retrieve them the value for int_dow does not get inflated. I think I am not understanding something, here is a code fragment from my CGI::Application run_mode:package AppSys::DBI; use Class::DBI::Iterator; use base 'Class::DBI::mysql'; AppSys::DBI->set_db('Main', 'DBI:mysql:appsys', '****', '****'); package AppSys::BusinessHours; use base AppSys::DBI; AppSys::BusinessHours->set_up_table("pr_businesshours"); AppSys::BusinessHours->has_a('int_dow' => 'AppSys::DOW'); package AppSys::DOW; use base AppSys::DBI; AppSys::DOW->set_up_table("as_dow");
Any clues please brethren?@ints = AppSys::BusinessHours->search( provider_id => $provider_id +, {order_by => 'int_dow'}); my @loh; #while ( my $day = $ints->next ) { foreach (@ints) { my $day = AppSys::BusinessHours->retrieve( $_->id ); my $hashref = { map { $_ => $day->get($_); } $day->columns }; push ( @loh, $hashref ); }
UPDATED: The thought just occurred to me that possibly the relationship is not inflated if I use the get method?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Inflating foreign key values in Class::DBI
by perrin (Chancellor) on Jan 13, 2004 at 20:47 UTC | |
|
Re: Inflating foreign key values in Class::DBI
by castaway (Parson) on Jan 13, 2004 at 20:58 UTC |