mrh30 has asked for the wisdom of the Perl Monks concerning the following question:

Hi there again,

I'm getting an error out of my code, and I don't really understand why I'm getting it, or what to do about it!

I'm using Class::DBI::Relationship::IsA to allow myself to subclass Users of my system. The Users package is as follows:
#!/usr/bin/perl package MyDB::Users; use base 'MyDB::DBI'; MyDB::Users->table('USERS'); MyDB::Users->columns( All => qw/USERNAME PASS USERTYPE EMAIL/); MyDB::Users->might_have( CANDIDATE => 'MyDB::Candidates' => qw/FIRSTNAME LASTNAME DISABLED +CV/); MyDB::Users->might_have( CLIENT => 'MyDB::Clients' => qw/NAME MAXROLES MAXCOMPETENCIES/); 1;
A User can be either a Client or a Candidate:
#!/usr/bin/perl package MyDB::Candidates; use base 'MyDB::DBI'; use MyDB::Users; MyDB::Candidates->table('CANDIDATES'); MyDB::Candidates->columns( All => qw/USERNAME FIRSTNAME LASTNAME DISABLED/ ); MyDB::Candidates->is_a( USERNAME => 'MyDB::Users' ); 1;
and
#!/usr/bin/perl package MyDB::Clients; use base 'MyDB::DBI'; use MyDB::Users; MyDB::Clients->table('CLIENTS'); MyDB::Clients->columns( All => qw/USERNAME NAME MAXROLES MAXCOMPETENCIES/); MyDB::Clients->is_a( USERNAME => 'MyDB::Users'); 1;
Anyway... The problem comes when in the code for the app itself I call
my @objs = MyDB::Clients->retrieve_all();
At which point I get the error:

Can't locate object method "username" via package "ctmclient" (perhaps you forgot to load "ctmclient"?) at Class/DBI/Relationship/IsA.pm line 311.

(ctmclient is the username of the one client which I have inserted into the database - it is in the Clients and Users tables correctly). Anyway, can anyone point me towards where I might be going wrong. The docs for IsA seem to be a bit sketchy at best.

Thanks in advance.

Mel

Replies are listed 'Best First'.
Re: Class::DBI::Relationship::IsA problem
by Taulmarill (Deacon) on Jul 28, 2005 at 12:32 UTC
    according to the docs from CDBI::R::IsA i think you have do give him the table not the class as second parameter. so i think MyDB::Clients->is_a( USERNAME => 'Users'); should work.
      Yeah, that was one of my early thoughts on the subject. My belief, however, is that the docs are wrong on this, as when you change the line as you suggest, you get compile-time errors!
      Is there anyone out there who can get me any further with this? I'm at a bit of a loss.