Created
April 28, 2017 16:28
-
-
Save chy-causer/d7541ca8e7f0f5fc5a317944b5b4d0cf to your computer and use it in GitHub Desktop.
Incorrect behaviour
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The diff below allows you to submit two titles to the blog application. | |
Had the validation not been there and had the developer just used $self->param('title'), I get the last supplied value. | |
However, using validation, this is not the case. | |
It looks like the behaviour of a 500 database type constraint failure is not necessarily so as DBD tries to stringify | |
this example. | |
Expected behaviour: | |
Title to be the last one supplied | |
Actual behaviour: | |
A stringification (if DBD can do it) of the two values '{"Title 1","Title 2"}' | |
There currently is no way to specify you want to use the last used value, or the inverse of extracting an arrayref of values if | |
just one is supplied. The patch at https://gist.github.com/chy-causer/21a6d749afe7e74a3436082df15e5aad is meant to allow for | |
# Only gives one title | |
$validation->required('title' => 'once'); | |
# Returns an array ref of foreign_key_ids => $FOO, even when only one value has been supplied | |
$validation->optional('foreign_key_ids' => 'as_array') | |
__DIFF__ | |
diff --git a/examples/blog/templates/posts/_form.html.ep b/examples/blog/templates/posts/_form.html.ep | |
index cb18a77..b3642cd 100644 | |
--- a/examples/blog/templates/posts/_form.html.ep | |
+++ b/examples/blog/templates/posts/_form.html.ep | |
@@ -2,6 +2,7 @@ | |
%= label_for title => 'Title' | |
<br> | |
%= text_field title => $post->{title} | |
+ %= text_field title => $post->{title} | |
<br> | |
%= label_for body => 'Body' | |
<br> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment