Subject: | 2 suggestions for InstantCRUD, and one possible bug |
These first two are not really bugs, just suggestions.
I'm using Catalyst-Example-InstantCRUD v 0.0.30 with Catalyst 5.80004
1) In the 'destroy' sub, change the forward to a redirect, otherwise,
all the links on the following list page are wrong.
# $c->forward('list');
$c->response->redirect($c->uri_for('list'));
2) When pulling options from a related table in
sub _options_from_resultset, it would be nice to have a way to pull in
something other than the PK field.
I overrode this routine and changed:
while( my $related_row = $related_rs->next ){
$field->add_option( $related_row->$pk =>
$related_row->$pk );
}
to:
while( my $related_row = $related_rs->next ){
$field->add_option( $related_row->$pk =>
$related_row->display_name || $related_row->$pk );
}
And then added an appropriate display_name method to each of my models.
But, I'm sure there is a better way to generalize that idea.
The third issue is a possible bug. But, I'm not sure. I'm using MySQL
tables with auto_increment on the PK. When start my test server and Add
an item to a table, it works perfectly the first time. But, if I try to
add a second item, it fails. It seem to try to UPDATE the previous
entry instead of INSERTing another new one.
Here is the debug output from the first, successful "Add":
SELECT me.id, me.name FROM shopping_centers me WHERE ( me.id IS NULL ):
INSERT INTO shopping_centers ( id, name) VALUES ( ?, ? ): 'NULL', 'aaaa'
[info] *** Request 13 (0.481/s) [23066] [Wed Jun 10 13:41:38 2009] ***
[debug] Body Parameters are:
.-------------------------------------+--------------------------------------.
| Parameter | Value
|
+-------------------------------------+--------------------------------------+
| foo | Add / Edit
|
| id |
|
| name | aaaa
|
'-------------------------------------+--------------------------------------'
[debug] "POST" request for "shoppingcenters/edit" from "76.111.124.231"
[debug] Path is "shoppingcenters/edit"
[debug] Found sessionid "7785eea4550ee9183f1182882b207741b673128a" in cookie
[debug] Restored session "7785eea4550ee9183f1182882b207741b673128a"
[debug] Redirecting to
"http://rh7.axion-it.com:3000/shoppingcenters/view/19"
[info] Request took 0.027832s (35.930/s)
.------------------------------------------------------------+-----------.
| Action | Time |
+------------------------------------------------------------+-----------+
| /auto | 0.007691s |
| /shoppingcenters/auto | 0.000682s |
| /shoppingcenters/edit | 0.012079s |
| /end | 0.000321s |
'------------------------------------------------------------+-----------'
SELECT me.id, me.name FROM shopping_centers me WHERE ( me.id = ? ): '19'
[info] *** Request 14 (0.519/s) [23066] [Wed Jun 10 13:41:38 2009] ***
[debug] "GET" request for "shoppingcenters/view/19" from "76.111.124.231"
[debug] Path is "shoppingcenters/view"
[debug] Arguments are "19"
[debug] Found sessionid "7785eea4550ee9183f1182882b207741b673128a" in cookie
[debug] Restored session "7785eea4550ee9183f1182882b207741b673128a"
[debug] Rendering template "shoppingcenters/view.tt"
[info] Request took 0.025501s (39.214/s)
And here is the output from the second, failed "Add":
SELECT me.id, me.name FROM shopping_centers me WHERE ( me.id IS NULL ):
UPDATE shopping_centers SET id = ?, name = ? WHERE ( id = ? ): 'NULL',
'bbbbb', '19'
uri_for called with undef argument at
/usr/lib/perl5/site_perl/5.8.8/Catalyst/Example/Controller/InstantCRUD.pm line
75
Use of uninitialized value in substitution (s///) at
/usr/lib/perl5/site_perl/5.8.8/Catalyst.pm line 1193.
[info] *** Request 22 (0.208/s) [23066] [Wed Jun 10 13:42:57 2009] ***
[debug] Body Parameters are:
.-------------------------------------+--------------------------------------.
| Parameter | Value
|
+-------------------------------------+--------------------------------------+
| foo | Add / Edit
|
| id |
|
| name | bbbbb
|
'-------------------------------------+--------------------------------------'
[debug] "POST" request for "shoppingcenters/edit" from "76.111.124.231"
[debug] Path is "shoppingcenters/edit"
[debug] Found sessionid "7785eea4550ee9183f1182882b207741b673128a" in cookie
[debug] Restored session "7785eea4550ee9183f1182882b207741b673128a"
[debug] Redirecting to "http://rh7.axion-it.com:3000/shoppingcenters/view"
[info] Request took 0.027284s (36.652/s)
.------------------------------------------------------------+-----------.
| Action | Time |
+------------------------------------------------------------+-----------+
| /auto | 0.007753s |
| /shoppingcenters/auto | 0.000578s |
| /shoppingcenters/edit | 0.011791s |
| /end | 0.000293s |
'------------------------------------------------------------+-----------'
[info] *** Request 23 (0.217/s) [23066] [Wed Jun 10 13:42:57 2009] ***
[debug] "GET" request for "shoppingcenters/view" from "76.111.124.231"
[debug] Path is "shoppingcenters/view"
[debug] Found sessionid "7785eea4550ee9183f1182882b207741b673128a" in cookie
[debug] Restored session "7785eea4550ee9183f1182882b207741b673128a"
[error] Caught exception in
Dw_Postings::Admin::Controller::ShoppingCenters->view "You need to pass
an id at
/usr/lib/perl5/site_perl/5.8.8/Catalyst/Example/Controller/InstantCRUD.pm line
87."
[info] Request took 0.021008s (47.601/s)
I found that if I run this app in CGI mode, so that nothing but the
session, survives between calls, this problem does not occur.
Thanks much for making this module, it is very helpful as a starting point.