Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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.

In reply to Re: DBI::Class relationship naming by Beatnik
in thread DBI::Class relationship naming by Beatnik

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (3)
    As of 2020-02-22 04:06 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      What numbers are you going to focus on primarily in 2020?










      Results (98 votes). Check out past polls.

      Notices?