I am working on a Catalyst app and to add data to three different tables in my database. Two of the three tables are for data and the third is a lookup table that uses the uniq ID from the other two tables. I can't seem to find a working method to populating the look up table.

This is what my database tables I am working with look like:

CREATE TABLE computer ( compid integer NOT NULL, compman character varying(128) NOT NULL, compmodel character varying(128) NOT NULL, modnum character varying(128) NOT NULL, os character varying(128) NOT NULL, errormsg character varying(128) NOT NULL, service character varying(128) NOT NULL, probdesc character varying(128) NOT NULL, diddiagnostic boolean DEFAULT false NOT NULL, complete smallint DEFAULT (0)::smallint NOT NULL, loginpw character varying(128) NOT NULL, comment character varying(255) NOT NULL, compsn character varying(128) NOT NULL, date timestamp NOT NULL, lastmod timestamp DEFAULT now() ); CREATE TABLE customers ( uniqid integer NOT NULL, firstname character varying(255) NOT NULL, lastname character varying(255) NOT NULL, email character varying(255) NOT NULL, phone character varying(13) NOT NULL, date timestamp NOT NULL, isbusstu boolean DEFAULT false NOT NULL, donations integer NOT NULL ); CREATE TABLE customerstocomputers ( custid integer NOT NULL, compid integer NOT NULL );

As for what I am trying to do is create the records in the customers and computer table then pull the data back to get the uniqe IDs (because they are auto incremented from Postgre)

my $newperson = eval { $customer_rs->create({ firstname => $params->{firstname}, lastname => $params->{lastname}, email => $params->{email}, phone => $params->{phone}, date => $date, donations => '0', }) }; my $newcomputer = eval { $computer_rs->create({ compman => $params->{compman}, compmodel => $params->{compmodel}, modnum => $params->{modnum}, os => $params->{os}, errormsg => $params->{errormsg}, service => $params->{service}, probdesc => $params->{probdesc}, loginpw => $params->{loginpw}, comment => $params->{comment}, compsn => $params->{compsn}, date => $date, }) }; my $customer = $customer_rs->find({ email => $params->{email} }); my $computer = $computer_rs->find({ compsn => $params->{compsn} }); eval { $c2c_rs->create({ custid => $customer->{uniqid}, compid => $computer->{compid}, }) };

Using Data::Dumper I can see that $customer and $computer is populated but how I am accessing them returns undef. What am I doing wrong here, or is there a better way to achieve my goal?


In reply to Catalyst and DBIC, lookup table question by vendion

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, details, 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, summary, 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.