<div dir="ltr">Not sure if that&#39;s the best way to do it or if it&#39;s a good approach, but I have a trait which is applied to all result classes.<div><br></div><div><div>TraitFor::Result::ForceNULL;</div><div>use strict;</div><div>use warnings;</div><div><br></div><div>my $null = undef;</div><div><br></div><div>sub insert</div><div>{</div><div>  my $self = shift;</div><div><br></div><div>  for my $col ($self-&gt;columns) {</div><div>    next unless defined $self-&gt;$col;</div><div>    next unless $self-&gt;$col eq &quot;&quot;;</div><div><br></div><div>    my $info = $self-&gt;result_source-&gt;column_info($col);</div><div>    $self-&gt;$col($null) if $info-&gt;{is_nullable};</div><div>  }</div><div>  return $self-&gt;next::method(@_);</div><div>}</div><div><br></div><div>sub update</div><div>{</div><div>  my $self      = shift;</div><div>  my %to_update = $self-&gt;get_dirty_columns;</div><div><br></div><div>  return $self-&gt;next::method(@_) unless keys %to_update;</div><div><br></div><div>  for my $col (keys %to_update) {</div><div>    next unless $to_update{$col} eq &quot;&quot;;</div><div>    my $info = $self-&gt;result_source-&gt;column_info($col);</div><div>    $self-&gt;{_column_data}{$col} = $null if $info-&gt;{is_nullable};</div><div>  }</div><div>  return $self-&gt;next::method(@_);</div><div>}</div><div><br></div><div>1;</div></div><div><br></div><div>Best regards</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 2, 2017 at 5:14 PM, Rajesh Kumar Mallah <span dir="ltr">&lt;<a href="mailto:mallah@redgrape.tech" target="_blank">mallah@redgrape.tech</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
By empty i mean string with length 0 ie &#39;&#39;<br>
<br>
__CODE__<br>
<br>
<br>
I am posting to rest endpoint Automagically generated via<br>
Catalyst::Controller::DBIC::<wbr>API  there is no explicit code hand<br>
written by me.And that is why looking for a global filter.<br>
<br>
There are three great virtues of a programmer; Laziness, Impatience and<br>
Hubris -- Larry Wall.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
&gt; Just curious: when you say &quot;prefilled with nothing&quot;, you mean the field is<br>
&gt; empty, or the field is filled with one or more white spaces (like &quot; &quot;), or<br>
&gt; the field is a &lt;select&gt; with the first &lt;option&gt; having the attribute<br>
&gt; &quot;value&quot; equals to &quot;&quot;? Or something else?<br>
&gt;<br>
&gt; gil<br>
&gt;<br>
&gt; On Thu, Mar 02, 2017 at 10:25:27AM -0500, Rajesh Kumar Mallah wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hi ,<br>
&gt;&gt;<br>
&gt;&gt; I want to transform request parameters in GET &amp; POST requests<br>
&gt;&gt; so that any thing which is empty (string) gets converted/replaced<br>
&gt;&gt; my perl&#39;s undef (and DBIC&#39;s NULL).<br>
&gt;&gt;<br>
&gt;&gt; Why i need that:<br>
&gt;&gt; ====================<br>
&gt;&gt; I have edit form in my web app and some fields in the edit form<br>
&gt;&gt; are prefilled with nothing. On submission the DB raises an exception<br>
&gt;&gt; that an empty string is being inserted to a integer field.<br>
&gt;&gt;<br>
&gt;&gt; Hence I feel like having a global filter that turns all blanks to<br>
&gt;&gt; undef.<br>
&gt;&gt;<br>
&gt;&gt; The question is where to put this global filter.<br>
&gt;&gt;<br>
&gt;&gt; Regds<br>
&gt;&gt; mallah.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; ______________________________<wbr>_________________<br>
&gt;&gt; List: <a href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a><br>
&gt;&gt; Listinfo: <a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst" rel="noreferrer" target="_blank">http://lists.scsys.co.uk/cgi-<wbr>bin/mailman/listinfo/catalyst</a><br>
&gt;&gt; Searchable archive:<br>
&gt;&gt; <a href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/" rel="noreferrer" target="_blank">http://www.mail-archive.com/<wbr>catalyst@lists.scsys.co.uk/</a><br>
&gt;&gt; Dev site: <a href="http://dev.catalyst.perl.org/" rel="noreferrer" target="_blank">http://dev.catalyst.perl.org/</a><br>
&gt;<br>
&gt; ______________________________<wbr>_________________<br>
&gt; List: <a href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a><br>
&gt; Listinfo: <a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst" rel="noreferrer" target="_blank">http://lists.scsys.co.uk/cgi-<wbr>bin/mailman/listinfo/catalyst</a><br>
&gt; Searchable archive:<br>
&gt; <a href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/" rel="noreferrer" target="_blank">http://www.mail-archive.com/<wbr>catalyst@lists.scsys.co.uk/</a><br>
&gt; Dev site: <a href="http://dev.catalyst.perl.org/" rel="noreferrer" target="_blank">http://dev.catalyst.perl.org/</a><br>
&gt;<br>
<br>
<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
List: <a href="mailto:Catalyst@lists.scsys.co.uk">Catalyst@lists.scsys.co.uk</a><br>
Listinfo: <a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst" rel="noreferrer" target="_blank">http://lists.scsys.co.uk/cgi-<wbr>bin/mailman/listinfo/catalyst</a><br>
Searchable archive: <a href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/" rel="noreferrer" target="_blank">http://www.mail-archive.com/<wbr>catalyst@lists.scsys.co.uk/</a><br>
Dev site: <a href="http://dev.catalyst.perl.org/" rel="noreferrer" target="_blank">http://dev.catalyst.perl.org/</a><br>
</div></div></blockquote></div><br></div>