[Catalyst] Catalyst model, again

Sean Davis sdavis2 at mail.nih.gov
Thu Jan 12 18:50:45 CET 2006


I have the following classes and ApacheAdmin::Model::DB is just for
connecting to the database--nothing unusual there.  With the test script at
the bottom, I get the following error:

Cannot load ApacheAdmin::Model::User without a primary key (username) with a
non-null value or another unique key with at least one non-null value. at
test.pl line 9

If I remove the inheritance from Catalyst::Model, everything works fine.
It's not too big a deal in practice--I don't NEED the catalyst::model
inheritance--but I'm curious why this doesn't work.

Thanks,
Sean


package ApacheAdmin::Model::User;

use strict;

use ApacheAdmin::Model::Base;
our @ISA = qw(ApacheAdmin::Model::Base);

__PACKAGE__->meta->table('users');

__PACKAGE__->meta->columns(
    username  => { type => 'varchar', not_null => 1 },
    pass      => { type => 'varchar' },
    groupname => { type => 'varchar', length => 50 },
);

__PACKAGE__->meta->primary_key_columns([ 'username' ]);

__PACKAGE__->meta->relationships(
    groups => {
        column_map    => { username => 'username' },
        foreign_class => 'ApacheAdmin::Model::Group',
        map_class     => 'ApacheAdmin::Model::UserGroupMap',
        map_from      => 'user',
        map_to        => 'group',
        type          => 'many to many',
    },
);

__PACKAGE__->meta->initialize;

1;


package ApacheAdmin::Model::Base;
use strict;

use ApacheAdmin::Model::DB;

use Rose::DB::Object;
use Catalyst::Model;
our @ISA = qw(Catalyst::Model Rose::DB::Object);

sub init_db { my $db = ApacheAdmin::Model::DB->new();
              $db->connect_option(AutoCommit => 0);
              $db->connect_option(RaiseError => 1);
              return $db; }

1;



#!/usr/bin/perl
use strict;
use lib '../lib';

use ApacheAdmin::Model::User;

my $user = ApacheAdmin::Model::User->new(username => 'doron');

$user->load();

print "";






More information about the Catalyst mailing list