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

I've used DBIx::Class to access some similar tables. Some of the methods around a table relationship puzzled me. On one of my tables, it worked but on the other one it didn't. Schema below (Postgres):
CREATE TABLE r1 ( id integer, name character varying(64), PRIMARY KEY (id) ); CREATE TABLE t1 ( id integer, groupnames integer REFERENCES r1(id), PRIMARY KEY (id) ); CREATE TABLE r2 ( id integer, name character varying(64), PRIMARY KEY (id) ); CREATE TABLE t2 ( id integer, groupname integer REFERENCES r2(id), PRIMARY KEY (id) );
So when I use dbicdump to generate my classes, everything seems to be fine, the has_many callers are mapped properly. Despite the fields called groupnames (t1) and groupname (t2), the relationship mapping only works with groupname. When using groupnames, the method will load the identifier and not the relationship value. I probably overlooked something in the DBIx::Class documentation about the naming conventions for table relationships. Since I cracked my head on this for a few days, thought I'd share this so others can avoid the same pitfalls.
use lib qw(lib); use DBIC::Schema; use Data::Dumper; my $schema = DBIC::Schema->connect("dbi:Pg:dbname=dbic; host=localhost +","pguser","pgpassword"); my $t1_rs = $schema->resultset('T1'); $query_rs = $t1_rs->search; while (my $account = $query_rs->next) { print Dumper $account->groupname->name; } my $t2_rs = $schema->resultset('T2'); $query_rs = $t2_rs->search; while (my $account = $query_rs->next) { print Dumper $account->groupname->name; }

... I'm belgian but I don't play one on TV.