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

Greetings fellow monks!

I am in the process of learning DBIx::Class and Catalyst. The examples below probably are not unique to Catalyst, however. At the moment, I am trying to wrap my mind around DBIx::Class relationships (yes, I have read the docs...and more).

The scenario is as follows:

I am presenting the following classes for constructive critique. I am particularly interested in whether or not I am declaring the intended relationships properly. If not, I would greatly appreciate your insight. Note that these classes are stored in separate files, and are documented with POD, which was not included in the examples.

package testDB::Member; use base qw / DBIx::Class /; __PACKAGE__->load_components(qw/ PK::Auto Core /); __PACKAGE__->table('members'); __PACKAGE__->add_columns(qw/ id name email password enabled /); __PACKAGE__->set_primary_key(qw/ id /); __PACKAGE__->has_many(profiles => 'testDB::Profile', 'membe +r_id'); __PACKAGE__->has_many(assigned_roles => 'testDB::AssignedRole', 'membe +r_id'); 1; package testDB::Profile; use base qw / DBIx::Class /; __PACKAGE__->load_components(qw/ PK::Auto Core /); __PACKAGE__->table('profiles'); __PACKAGE__->add_columns(qw/ id member_id server name /); __PACKAGE__->set_primary_key(qw/ id /); __PACKAGE__->belongs_to(member => 'testDB::Member', 'membe +r_id'); __PACKAGE__->has_many(assigned_roles => 'testDB::AssignedRole', 'profi +le_id'); 1; package testDB::AssignedRole; use base qw / DBIx::Class /; __PACKAGE__->load_components(qw/ PK::Auto Core /); __PACKAGE__->table('assigned_roles'); __PACKAGE__->add_columns(qw/ id member_id profile_id role_id /); __PACKAGE__->set_primary_key(qw/ id /); __PACKAGE__->belongs_to(member => 'testDB::Member', 'member_id'); __PACKAGE__->belongs_to(profile => 'testDB::Profile', 'profile_id'); __PACKAGE__->belongs_to(role => 'testDB::Role', 'role_id'); 1; package testDB::Role; use base qw / DBIx::Class /; __PACKAGE__->load_components(qw/ PK::Auto Core /); __PACKAGE__->table('roles'); __PACKAGE__->add_columns(qw/ id tag description enabled /); __PACKAGE__->set_primary_key(qw/ id /); __PACKAGE__->has_one(role_type => 'testDB::RoleType', 'role_ +type_id'); __PACKAGE__->has_many(assigned_roles => 'testDB::AssignedRole', 'role_ +id'); 1; package testDB::RoleType; use base qw / DBIx::Class /; __PACKAGE__->load_components(qw/ PK::Auto Core /); __PACKAGE__->table('role_types'); __PACKAGE__->add_columns(qw/ id name /); __PACKAGE__->set_primary_key(qw/ id /); 1;

Thank you for your time and wisdom. --Akoya

Replies are listed 'Best First'.
Re: DBIx::Class relationships
by zby (Vicar) on Oct 19, 2007 at 16:22 UTC
    It looks perfectly sane to me.