Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

coerce blank strings to nil values for boolean and integer fields

#860

This patch fixes ActiveRecord to consistently coerce blank strings to nil values for boolean and integer fields. Prior to this change, blank strings were coerced to false for booleans, while integer fields coerced empty strings to nil and non-empty blank strings (i.e. containing whitespace) to 0.

Apparently there's a bit of controversy over this functionality. Please see this thread: http://groups.google.com/group/r...

Reported by Josh Susser · August 19th, 2008 @ 07:53 PM

State: resolved
Milestone: none
Assigned to: Michael Koziarski Michael Koziarski
Importance: High

Activity

  1. Tom Ward
    Tom Ward

    Coercing blank strings to nil for non-string columns makes a whole load of sense to me. A definite +1.

    August 19th, 2008 @ 11:28 PM

  2. Michael Koziarski
    Michael Koziarski
    • State changed from new to committed

    August 21st, 2008 @ 03:48 PM

  3. Jeremy Kemper
    Jeremy Kemper
    • State changed from committed to incomplete
    • Milestone cleared.

    This causes value_to_boolean(false) to return nil.

    August 22nd, 2008 @ 05:27 AM

  4. Repository
    Repository

    (from [a5eb297424f68583636b762686726bc0c84703c0]) Revert "coerce blank strings to nil values for boolean and integer fields"

    This reverts commit aee14630d4dc0856e597794cc731fac68c2d2e34.

    [#860 coerce blank strings to nil values for boolean and integer fields state:incomplete] http://github.com/rails/rails/co...

    August 22nd, 2008 @ 06:14 AM

  5. Michael Koziarski
    Michael Koziarski

    Kinda disconcerting this didn't hit any test failures, so we probably need one.

    It should check .is_a? String

    August 22nd, 2008 @ 06:22 AM

  6. Josh Susser
    Josh Susser

    Updated patch to fix issue. Changed the tests to actually test a :boolean field instead of an :integer one, so there is real coverage now (instead of pretend).

    August 22nd, 2008 @ 11:44 PM

  7. Repository
    Repository
    • State changed from incomplete to resolved

    (from [e48e77e0222292176cd9f68658dd54524f582d9b]) coerce blank strings to nil values for boolean and integer fields

    [#860 coerce blank strings to nil values for boolean and integer fields state:resolved] http://github.com/rails/rails/co...

    August 23rd, 2008 @ 12:28 AM