[Dbix-class] DBIx how to update_or_create a table with primary index is autoincrement ? getting erroneous data

Rajeev Prasad rp.neuli at yahoo.com
Thu Sep 27 17:40:04 GMT 2012


so far, I do not, but I want one filed to be uniq, lets call it field1. so =
should i set a uniq constraint on it, and then use that field in update_or_=
create? rather than the primary index?

ty.




________________________________
 From: Ronald J Kimball <rkimball at pangeamedia.com>
To: Rajeev Prasad <rp.neuli at yahoo.com>; DBIx::Class user and developer list=
 <dbix-class at lists.scsys.co.uk> =

Sent: Thursday, September 27, 2012 12:27 PM
Subject: Re: [Dbix-class] DBIx how to update_or_create a table with primary=
 index is autoincrement ? getting erroneous data
 =


On Thu, Sep 27, 2012 at 12:55 PM, Rajeev Prasad <rp.neuli at yahoo.com> wrote:

friends,
>
>I have a Table to update (empty right now), and the regularly 'update' exi=
sting info with changes AND add any new record which come up.
>
>source data is coming from file. one record per line.
>
>=A0=A0=A0 =A0=A0=A0 my @my_arr;=A0 #has 500 uniq entries
>
>=A0=A0=A0 =A0=A0=A0 $schema->resultset('Mytable')->update_or_create(
>=A0=A0=A0 =A0=A0=A0 {
>=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 field1 =3D> $my_arr[0],
>=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 field2 =3D> $my_arr[1],
>=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 field3 =3D> $my_arr[2],
>=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 ...
>=A0=A0=A0 =A0=A0=A0 },
>=A0=A0=A0 =A0=A0=A0 {key =3D>'primary'}=A0=A0=A0 #field_id, auto increment=
 value this field is NOT supplied in variables above.
>=A0=A0=A0 =A0=A0=A0 );
>
>
>What is happening is: DBIX is first adding the 'first' record, then updati=
ng it with consecutive records!!! it is not creating a fresh record for any=
 record in the file. so after it finishes running, I am left with one recor=
d in Table which is updated 500 times, and has the last record in file as t=
he table record.
>
>
>how to fix this?
>

You've asked update_to_create() to find the existing row based solely on th=
e primary key, but you haven't provided a value for the primary key. =A0The=
refore, it assumes that all the rows are the same row.

Do you have any unique constraints on this table other than primary key?

Ronald
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120927/99f=
847cf/attachment.htm


More information about the DBIx-Class mailing list