[Catalyst] Can't get my db classes to have relations

Dennis Daupert ddaupert at sbcglobal.net
Sat Jul 8 01:19:28 CEST 2006


I'm stuck on one point regarding setting up db relationships. 

I keep getting this error:

<snip>"Cannot load schema class 'Catapult::Schema::CatapultDB': DBIx::Class::Relationship::BelongsTo::belongs_to(): Can't infer join condition for user on Catapult::Schema::CatapultDB::UserRoles; unable to load CatapultDB::Users at /home/perl/cat/Catapult/script/../lib/Catapult/Schema/CatapultDB/UserRoles.pm line 23

******************
Line 23 of CatapultDB::UserRoles is:

__PACKAGE__->belongs_to(user => 'CatapultDB::Users', 'user_id');
******************

Here are all the gory details. I've been over them so many times my eyes are starting to smart while my brain is definitely starting to dumm ;-)

best,

/dennis

#--------
package Catapult::Schema::CatapultDB;

use warnings;
use strict;
use base qw/DBIx::Class::Schema/;

__PACKAGE__->load_classes(qw/Users UserRoles Roles Quotes Category States/);

#-------------------------------------------
package Catapult::Schema::CatapultDB::Users;

use base qw/DBIx::Class/;

__PACKAGE__->load_components(qw/ PK::Auto Core HTMLWidget /);
# Set the table name
__PACKAGE__->table('users');
# Set columns in table
__PACKAGE__->add_columns(qw/id fname lname address1 address2 city state zip email username password active /);
# Set the primary key for the table
__PACKAGE__->set_primary_key(qw/id/);
#
# Set relationships:
#
__PACKAGE__->has_many(map_user_role => 'CatapultDB::UserRoles', 'user_id');
#-------------------------------------------
package Catapult::Schema::CatapultDB::Roles;

use base qw/DBIx::Class/;

__PACKAGE__->load_components(qw/ PK::Auto Core /);
# Set the table name
__PACKAGE__->table('roles');
# Set columns in table
__PACKAGE__->add_columns(qw/id role/);
# Set the primary key for the table
__PACKAGE__->set_primary_key(qw/id/);
#
# Set relationships:
#
__PACKAGE__->has_many(map_user_role => 'CatapultDB::UserRoles', 'role_id');
#-------------------------------------------
package Catapult::Schema::CatapultDB::UserRoles;

use base qw/DBIx::Class/;

# Load required DBIC stuff
__PACKAGE__->load_components(qw/PK::Auto Core/);
# Set the table name
__PACKAGE__->table('user_roles');
# Set columns in table
__PACKAGE__->add_columns(qw/user_id role_id/);
# Set the primary key for the table
__PACKAGE__->set_primary_key(qw/user_id role_id/);
#
# Set relationships:
#
__PACKAGE__->belongs_to(user => 'CatapultDB::Users', 'user_id');

__PACKAGE__->belongs_to(role => 'CatapultDB::Roles', 'role_id');
#-------------------------------------------
postgresql db schema:
#-------------------------------------------
CREATE TABLE users (
  id          SERIAL       NOT NULL PRIMARY KEY,
  fname        varchar(20) NOT NULL,
  lname        varchar(20) NOT NULL,
  address1     varchar(80),
  address2     varchar(80),
  city         varchar(20),
  state        varchar(4),
  zip          integer,
  email           varchar(80),
  username     varchar(20),
  password     varchar(20),
  active       BOOLEAN     NOT NULL default True
);
#-------------------------------------------
CREATE TABLE roles (
  id          SERIAL       NOT NULL PRIMARY KEY,
  role        varchar(20)  NOT NULL
);
#-------------------------------------------
CREATE TABLE user_roles (
  user_id integer,
  role_id integer,
  PRIMARY KEY (user_id, role_id)
);
#-------------------------------------------

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060707/e54b961f/attachment.htm 


More information about the Catalyst mailing list