Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: DBI::Class relationship naming

by Beatnik (Parson)
on Jan 01, 2017 at 10:59 UTC ( #1178766=note: print w/replies, xml ) Need Help??


in reply to DBI::Class relationship naming

Complete code (schemas etc) with unambiguous field names:
#!/usr/bin/perl 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) # LOOK HERE! { print Dumper $account->fieldwith->name; } # DOES NOT WORK WITH print Dumper $account->fieldwiths->name; # METHOD HAS NO *S* IN IT my $t2_rs = $schema->resultset('T2'); $query_rs = $t2_rs->search; while (my $account = $query_rs->next) { print Dumper $account->fieldwithout->name; } __DATA__ CREATE DATABASE dbic WITH OWNER = pguser ENCODING = 'UTF8' TABLESPACE = pg_default LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8' CONNECTION LIMIT = -1; GRANT ALL ON DATABASE ng TO postgres; REVOKE CONNECT ON DATABASE pguser FROM PUBLIC; GRANT CONNECT ON DATABASE ng TO pguser; \c dbic CREATE TABLE r1 ( id integer, name character varying(64), PRIMARY KEY (id) ) WITH ( OIDS=TRUE ); ALTER TABLE r1 OWNER TO pguser; CREATE TABLE t1 ( id integer, fieldwiths integer REFERENCES r1(id), PRIMARY KEY (id) ) WITH ( OIDS=TRUE ); ALTER TABLE t1 OWNER TO pguser; CREATE TABLE r2 ( id integer, name character varying(64), PRIMARY KEY (id) ) WITH ( OIDS=TRUE ); ALTER TABLE r2 OWNER TO pguser; CREATE TABLE t2 ( id integer, fieldwithout integer REFERENCES r2(id), PRIMARY KEY (id) ) WITH ( OIDS=TRUE ); ALTER TABLE t2 OWNER TO pguser; REVOKE CONNECT ON DATABASE dbic FROM PUBLIC; GRANT CONNECT ON DATABASE dbic TO pguser; REVOKE ALL ON ALL TABLES IN SCHEMA public FROM PUBLIC; GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO pguser; dbicdump -o dump_directory=./lib \ -o components='["InflateColumn::DateTime"]' \ -o debug=1 \ DBIC::Schema \ 'dbi:Pg:dbname=dbic; host=localhost' \ pguser \ pgpassword delete from t1; delete from r1; insert into r1(id, name) values (1, 'Alpha'); insert into r1(id, name) values (2, 'Bravo'); insert into r1(id, name) values (3, 'Charlie'); insert into t1(id, fieldwiths) values(1, 1); insert into t1(id, fieldwiths) values(2, 2); insert into t1(id, fieldwiths) values(3, 3); delete from t2; delete from r2; insert into r2(id, name) values ('1', 'Alpha'); insert into r2(id, name) values ('2', 'Bravo'); insert into r2(id, name) values ('3', 'Charlie'); insert into t2(id, fieldwithout) values(1, '1'); insert into t2(id, fieldwithout) values(2, '2'); insert into t2(id, fieldwithout) values(3, '3');


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

Replies are listed 'Best First'.
Re^2: DBI::Class relationship naming
by soonix (Abbot) on Jan 01, 2017 at 19:27 UTC
    Probably a red herring, but "fieldwiths" and "fieldwithout" share a common prefix of length 9, as do "groupnames" and "groupname" (also length 9).
      That would be the easy explanation.. Unfortunately, the production fieldnames are 20+ characters long and the behavior is the same.


      Greetz
      Beatnik
      ... I'm belgian but I don't play one on TV.
        I know that Postgres can handle names of 64 characters, but in the code above you call it a method. I know next to nothing about DBIC, but if it uses XS/C/C++, there could happen some name mangling on the way from field name to method name.

        Does the problem persist, when the names differ already in the first few characters?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1178766]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2019-07-18 03:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?