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 => 'pidhack_1',
   imi => 'imix002',
)->update(pid => 'pidhack_2');

2007/3/6, John Ramsden-Developer <[EMAIL PROTECTED]>:


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=HASH(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 = ?
   WHERE ( imi = ? AND pid = ? ): `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 = ?
   WHERE ( imi = ? AND pid = ? ): `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/[email protected]/

_______________________________________________
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/[email protected]/

Reply via email to