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