Simon, that is a clever plugin. In fact, maybe we will start using it, since
it solves the leading and trailing spaces issues systematically. I just need
to think about if there is ever a time we need to preserve the spaces.
Perhaps you could enhance your plugin to allow some properties to opt-out?
In any case, I feel that a blank string should be treated as nil right in
dm-core. And for Integer fields this is essential.

..tony..

On Mon, Oct 12, 2009 at 1:19 PM, Simon Harris <[email protected]>wrote:

>
> Have you tried my dm-trimmer plugin?
> Http://github.com/harukizaemon/dm-trimmer
>
> On Oct 13, 6:20 am, Tony Mann <[email protected]> wrote:
> > I could not find an existing bug report filed, so I submitted a
> > ticket<
> http://datamapper.lighthouseapp.com/projects/20609-datamapper/tickets...>
> > with
> > the proposed fix.
> > ..tony..
> >
> >
> >
> > On Mon, Oct 12, 2009 at 12:10 PM, Tony Mann <[email protected]>
> wrote:
> > > I came up with what seems like a decent fix. In Datamapper::Property I
> > > added these lines at the head of typecast_to_numeric:
> > > def typecast_to_numeric(value, method)
> > >       if value.is_a?(String) && value.strip.empty?
> > >         nil
> > >       elsif...
> >
> > > If this seems like a reasonable approach, I can submit a bug and patch
> (or
> > > perhaps a bug is filed already).
> >
> > > ..tony..
> >
> > > On Mon, Oct 12, 2009 at 11:53 AM, Tony Mann <[email protected]>
> wrote:
> >
> > >> In DM 0.10.1, if you pass a blank string into an Integer property, you
> get
> > >> the following exception when using MySQL:
> >
> > >> DataObjects::SQLError: Incorrect integer value: '' for column 'num' at
> row
> > >> 1
> >
> > >> Here is the code that shows the issue:
> >
> > >>http://gist.github.com/208625
> > >> The causes major problems when submitting forms in Merb, since blank
> > >> fields are passed as in as blank string parameter values, and these
> > >> parameter values are generally passed right into a Resource#update
> call.
> > >> This problem did not occur in 0.9.
> >
> > >> I looked at the DM code, but I could not find an obvious place to add
> code
> > >> to massage the blank strings to nils. Any suggestions?
> >
> > >> ..tony..
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to