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

Ronald J Kimball rkimball at pangeamedia.com
Thu Sep 27 17:27:44 GMT 2012


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'
> existing info with changes AND add any new record which come up.
>
> source data is coming from file. one record per line.
>
>         my @my_arr;  #has 500 uniq entries
>
>         $schema->resultset('Mytable')->update_or_create(
>         {
>             field1 =3D> $my_arr[0],
>             field2 =3D> $my_arr[1],
>             field3 =3D> $my_arr[2],
>              ...
>         },
>         {key =3D>'primary'}    #field_id, auto increment value this field=
 is
> NOT supplied in variables above.
>         );
>
> What is happening is: DBIX is first adding the 'first' record, then
> updating 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 record in Table which is updated 500 times, and has the last record in
> file as the table record.
>
> how to fix this?
>

You've asked update_to_create() to find the existing row based solely on
the primary key, but you haven't provided a value for the primary key.
 Therefore, 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/ebb=
ad2c2/attachment-0001.htm


More information about the DBIx-Class mailing list