[Dbix-class] Updating part of a composite key

Oleg Pronin syber.rus at gmail.com
Tue Mar 13 23:27:23 GMT 2007


As far as i know DBIx::Class is unable to change primary key of a fetched
row (single or composite).
(because it will search for a record with new keys while you need the old
one).

I think this could be done by updating your record without fetching
(all-in-one query).
$schema->resultset('Broadcast')->search(
    pid =3D> 'pidhack_1',
    imi =3D> 'imix002',
)->update(pid =3D> 'pidhack_2');

2007/3/6, John Ramsden-Developer <John.Ramsden2 at bbc.co.uk>:
>
>
> I have a table 'broadcast', with a foreign key 'pid' to a table
> 'version',
> and with primary key a composite of 'pid' and 'imi', i.e.:
>
>   broadcast:                              version:
>
>      pid  } broadcast  ----------->         pid  } version
>      imi  }  key 0                                  key 0
>        :::                                   :::
>
> I want to write a test script that uses DBIx::Class to set up some
> records, represented by $broadcast, $version_1, and $version_2,
> such that initially $broadcast links to $version_1 and then is
> changed by the following to link to $broadcast_2:
>
>   $broadcast->version($version_2);
>
> However, when I run the test it displays the following error
> (referring to the line containing this call):
>
>   Can't update Broadcast=3DHASH(0x2d72c14): row not found at
> t/unit/misc/hack.t
>
> The SQL log showed that this call led to the following SQL:
>
>   UPDATE broadcast SET pid =3D ?
>    WHERE ( imi =3D ? AND pid =3D ? ): `pidhack_2', `imix002', `pidhack_2'
>
> In other words, it is using the required new key value in the WHERE
> clause,
> instead of the current key value i.e. obviously _should_ be (in this
> case):
>
>   UPDATE broadcast SET pid =3D ?
>    WHERE ( imi =3D ? AND pid =3D ? ): `pidhack_2', `imix002', `pidhack_1'
>
> Is there likely to be a problem with DBIx::Class updating parts of
> composite
> Keys using the above?
>
> Impressive though it is, I realize DBIx::Class it can't be infallible,
> and
> maybe in this situation it needs things spelled out more explicitly.
>
> If so, can anyone suggest an alternative format for the above call,
> or some extra information I need to include in the schema definition?
>
> Thanks in advance.
>
>
> Cheers
>
> John R Ramsden
>
> http://www.bbc.co.uk/
> This e-mail (and any attachments) is confidential and may contain personal
> views which are not the views of the BBC unless specifically stated.
> If you have received it in error, please delete it from your system.
> Do not use, copy or disclose the information in any way nor act in
> reliance on it and notify the sender immediately.
> Please note that the BBC monitors e-mails sent or received.
> Further communication will signify your consent to this.
>
>
> _______________________________________________
> List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> Searchable Archive:
> http://www.mail-archive.com/dbix-class@lists.rawmode.org/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20070314/84b=
6391a/attachment.htm


More information about the Dbix-class mailing list