The return from the ->search looks like
$VAR1 = \bless( { 'sysid' => '158' }, 'Lib::Systems' ); $VAR1 = \bless( { 'sysid' => '1065' }, 'Lib::Systems' ); $VAR1 = \bless( { 'sysid' => '1066' }, 'Lib::Systems' );
Just for kicks I tried the ->retrieve_all and then filtered out the returns for the rows I wanted and that didn't work either.
So we know 2 things:
1. Something about using the Class::DBI wrapper functions isn't working (using pure DBI does)
2. this worked fine before autocommit was turned off
At 03:39 PM 5/19/2004, Perrin Harkins wrote:
On Wed, 2004-05-19 at 18:08, Dave Boodman wrote: > breakthrough!
Cool!
> focusing on the view code here: > > this doesn't work: > > foreach my $obj (Lib::Systems->search(cid=>$cid)) { > my %e = map { $_ => $obj->$_ } Lib::Systems->columns; > push @out, \%e; > } > > this does: > > my $db = Lib::Systems->dbh; > my $sth = $db->prepare("select * from systems where cid='$cid'"); > $sth->execute; > while (my $obj = $sth->fetchrow_hashref) { > my %e = map { $_ => $obj->{$_} } Lib::Systems->columns; > push @out, \%e; > }
I would add some logging (maybe with Data::Dumper) to find out exactly what Lib::Systems->search(cid=>$cid) is bringing back.
> package Lib::Systems; > > use strict; > > use base qw( Lib::DBI ); > > Lib::Systems->table('systems'); > Lib::Systems->columns(All => qw( sysid cid machine dir veid > os_template hostname gigs start_date cancel_date stop_date sysaudit > )); > Lib::Systems->columns(Ordered => qw( machine dir veid hostname gigs > os_template start_date cancel_date stop_date sysaudit )); > Lib::Systems->has_many(ip => 'Lib::Ipmap', 'sysid'); > Lib::Systems->has_many(customer => 'Lib::Customers', 'cid');
I think this is the source of your problem. What is the primary key for this table? Your code above will make Class::DBI think that the primary key is "sysid", but it looks like maybe both sysid and cid are primary keys. You can declare multi-column primary keys like this:
__PACKAGE__->columns(Primary => qw( sysid cid ) );
- Perrin
-- Report problems: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html List etiquette: http://perl.apache.org/maillist/email-etiquette.html