For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > September 2006 > issue with an object, and an array of objects









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author issue with an object, and an array of objects
energy.keeper@gmail.com

2006-09-30, 10:00 pm

Hey 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,
</keeper>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com