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?