issue with an object, and an array of objects
am 01.10.2006 03:26:14 von energy.keeperHey all,
I'm using Class::DBI in conjunction with Postgres to pull records from
the database, but things are comming out a little off what i'd expect.
My package for Users:
______________________________________________
package CyberCMS::Users;
use base CyberCMS::DBI;
use Class::DBI::Plugin::AggregateFunction;
use Class::DBI::Pager;
use Class::DBI::AbstractSearch;
CyberCMS::Users->table('users');
CyberCMS::Users->columns(All=> qw / id username password email role
joined / );
CyberCMS::Users->mk_aggregate_function( max => 'maximum' );
1;
__END__
______________________________________________
And a sub rutine that uses this class
______________________________________________
############################################################ #####
# getUserById: returns a user object given the user id #
############################################################ #####
sub getUserById {
my $self=shift;
my $params={@_};
return undef if (! $params->{id});
my $user = CyberCMS::Users->retrieve(id=>$params->{id});
if (! $user) {
$self->setLastError(201, 'That User Id does not
exist!');
return undef;
} else {
return $user;
};
};
_______________________________________________
What happens here is that i should be able to (acording to my thoughts)
be able to do the folowing:
use strict;
use warnings;
use CyberCMS;
my $c = new CyberCMS;
my $user = $c->getUserByUsername(id=>$id);
__________________________________________
and that will get the entire record related to that user from the DB.
except that i dont :P
What I end up with is this as produced by Data::Dumper
$VAR1 = bless( {
'id' => '15'
}, 'CyberCMS::Users' );
me thinks it should look more like:
$VAR1 = bless ({
'id' => '15',
'username' => 'keeper',
'password' => 'cyzgolbleygoop',
'email' => 'an.email@adress.ext',
'role' => '1',
'joined' => 'timestamp'
});
__________________________
so why is all the data not comming from the DB?
Database = postgres BTW;
Thanks for any help,