[Dbix-class] Bug(?) updating (multi) PKs

Paul Makepeace paulm at paulm.com
Mon Dec 11 00:42:40 GMT 2006


I have a schema: [publication <- publication_source -> source] and I'm
trying to update the source_uid in the publication_source join table
for a given publication. My strategy is to look for the row, if it
exists update the source_uid, or create the join table row.

    	my @ps = $publication->publication_source({ rank => $rank });
  	if (@ps) {
  		$ps[0]->source_uid($source_uid);
  		$ps[0]->update;
  	} else {
  		$publication->add_to_publication_source({ rank => $rank,
source_uid => $source_uid });
  	}

The problem comes that upon update the system attempts to identify
which row to update using the *new* value of source_uid. Witness:

       UPDATE publication_source SET source_uid = ? WHERE (
publication_uid = ? AND rank = ? AND source_uid = ? ) (`282', `4355',
`2', `282')

So it's apparently not maintaining the old PK.

Does this look right?

How are other people updating join tables?! I'm guessing they're
either not declaring the row to be a multi-PK or doing some
create/delete dance. Either way this seems borken to me. Is it?

On a different but related note, given I have all my has_many and
many_to_many set up correctly, is there some way of doing my block of
code above more tidily with whatever accessors are available?

Paul

Appendix,

__PACKAGE__->table('publication_source');
__PACKAGE__->add_columns(qw/
rank
publication_uid
source_uid
/);
__PACKAGE__->set_primary_key(qw/rank publication_uid source_uid/);

Publication has, (Source the mirror),

__PACKAGE__->has_many(publication_source =>
'IDL::Schema::PublicationSource', 'publication_uid');
__PACKAGE__->many_to_many(sources => 'publication_source', 'source');



More information about the Dbix-class mailing list