Re: [Maypole] edit by unique field

From: Marcus Ramberg (marcus at thefeed.no)
Date: Wed Oct 06 2004 - 00:43:13 BST


On 5. okt. 2004, at 22.44, Kevin Connor wrote:

> out-of-the-box Maypole provides edit functionality using a numeric
> primary key in the url:
>
> beerdb/beer/edit/1

Actually, it provides edit functionality using the primary key in the
url, not just numeric ones.

> I'd like to support url's of the following form:
>
> beerdb/beer/edit/amberlight
>
> (presuming amberlight is the value for a unique field)
>
> I'm thinking along REST principles. It should bring up the add new
> page
> if the value doesn't exist.
>
> Anyway, it seems like to do it would mean overriding $class->retrieve.
>
> see the call to
> my $obj = $class->retrieve( $r->{args}->[0] );
> within
> Maypole::Model::Base::process
>
> Thoughts? Is this documented somewhere I've missed?

What you want is probably a custom action rather than overriding
retrieve.

in your cdbi class you would populate your object using something like

sub edit : Exported {
   my ($self,$r) = @_;
   $r->objects( [ $self->search(foo=>$r->{args}]);
}

or use your unique string as the primary key of the table (with
whatever performance gotchas that might bring).

Marcus - Who is going to bed

_______________________________________________
maypole mailing list
maypole at lists.netthink.co.uk
http://lists.netthink.co.uk/listinfo/maypole



This archive was generated by hypermail 2.1.3 : Thu Feb 24 2005 - 22:25:56 GMT