[Catalyst-commits] r8172 - in
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk: .
lib/CatalystX/CRUD/Controller
karpet at dev.catalyst.perl.org
karpet at dev.catalyst.perl.org
Thu Jul 31 17:42:29 BST 2008
Author: karpet
Date: 2008-07-31 17:42:29 +0100 (Thu, 31 Jul 2008)
New Revision: 8172
Modified:
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/Changes
CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/lib/CatalystX/CRUD/Controller/RHTMLO.pm
Log:
support multi-column PKs
Modified: CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/Changes
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/Changes 2008-07-30 20:23:45 UTC (rev 8171)
+++ CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/Changes 2008-07-31 16:42:29 UTC (rev 8172)
@@ -50,4 +50,6 @@
* field_names() now requires $c (context) be passed
+0.13 xxx
+ * change form_to_object() to support PKs of multiple columns
Modified: CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/lib/CatalystX/CRUD/Controller/RHTMLO.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/lib/CatalystX/CRUD/Controller/RHTMLO.pm 2008-07-30 20:23:45 UTC (rev 8171)
+++ CatalystX-CRUD/CatalystX-CRUD-Controller-RHTMLO/trunk/lib/CatalystX/CRUD/Controller/RHTMLO.pm 2008-07-31 16:42:29 UTC (rev 8172)
@@ -4,7 +4,7 @@
use Carp;
use Class::C3;
-our $VERSION = '0.12';
+our $VERSION = '0.13';
=head1 NAME
@@ -116,10 +116,10 @@
my $obj = $c->stash->{object};
my $obj_meth = $self->init_object;
my $form_meth = $self->init_form;
- my $pk = $self->primary_key;
-
+
# id always comes from url but not necessarily from form
- my $id = $c->req->params->{$pk} || $c->stash->{object_id};
+ my $id = $c->stash->{object_id};
+ my %pk = $self->get_primary_key( $c, $id );
# initialize the form with the object's values
# TODO this might not work if the delegate() does not have
@@ -128,7 +128,9 @@
# set param values from request
$form->params( $c->req->params );
- $form->param( $pk => $id );
+ for my $field ( keys %pk ) {
+ $form->param( $field => $pk{$field} );
+ }
# override form's values with those from params
# no_clear is important because we already initialized with object
@@ -151,22 +153,26 @@
# this is same objection as $form_metho call above
$form->$obj_meth($obj);
- # set id explicitly since there's some bug
- # with param() setting it in save()
- $obj->$pk($id);
+ # set PK(s) explicitly
+ for my $field ( keys %pk ) {
+ $obj->$field( $pk{$field} );
+ }
# let serial column work its magic
- $obj->$pk(undef)
- if ( !$obj->$pk || $obj->$pk eq '0' || $id eq '0' );
+ # if this is a first-time save (create)
+ if ( scalar( keys %pk ) == 1 or $id eq '0' ) {
+ my ( $field, $value ) = each %pk;
+ $obj->$field(undef)
+ if ( !$obj->$field || $obj->$field eq '0' || $value eq '0' );
+ }
- #carp "object $pk == $id ? " . $obj->$pk;
-
return $obj;
}
=head2 do_search( I<context>, I<arg> )
-Makes form values sticky then calls the base do_search() method with NEXT.
+Makes form values sticky then calls the base do_search() method with
+next::method().
=cut
More information about the Catalyst-commits
mailing list