Simon Flack <sf at flacks.net> wrote:
>
> On Sun, 05 Dec 2004 17:56:27 +0100, Marcus Ramberg wrote
> > Hi. Some person in #maypole alerted me to the fact that
> > Maypole::Model::Base::process will break with compound primary keys,
I'm that person :)
> I don't think we need to duplicate the code in Maypole::Model::Base.
> How about something like this:
FWIW, I think this approach is cleaner.
> sub Maypole::Model::Base::process {
> my ( $class, $r ) = @_;
> my $method = $r->action;
> return if $r->{template}; # Authentication has set this, we're done.
>
> $r->{template} = $method;
> $r->objects( [] );
> - my $obj = $class->retrieve( $r->{args}->[0] );
> + my $obj = $class->retrieve( $class->get_object_id($r) );
> $r->objects( [$obj] ) if $obj;
> $class->$method( $r, $obj, @{ $r->{args} } );
> }
Except that this doesn't work:
> sub Maypole::Model::CDBI::get_object_id {
> my ( $class, $r ) = @_;
> if (@{$class->primary_columns} > 1) {
primary_columns is an array, not a ref.
> my %pks;
> @pks{@{$class->primary_keys}}=(@{$r->{args}});
s/keys/columns/
> return \%pks;
retrieve wants a hash, not a ref.
> }
> return $class->SUPER::get_object_id($r);
> }
Here's a version that actually works:
sub get_object_id {
my ( $class, $r ) = @_;
my @pcs = $class->primary_columns;
if (@pcs > 1) {
my %pks;
@pks{@pcs}=(@{$r->{args}});
return %pks;
}
return $class->SUPER::get_object_id($r);
}
-- ilmari_______________________________________________ maypole-dev mailing list maypole-dev at lists.netthink.co.uk http://lists.netthink.co.uk/listinfo/maypole-dev
This archive was generated by hypermail 2.1.3 : Thu Feb 24 2005 - 22:25:57 GMT