collectiveidea / clear_empty_attributes
- Source
- Commits
- Network (1)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
805d67a
commit 805d67a0efbb00ed9291fdd0add09bdfeec690ec
tree ddc5551b0e812b4eead4aa1d3664e4ade92cacbb
parent 7ab48309eb1c52ed78f36444b9a4617d8c7b1824
tree ddc5551b0e812b4eead4aa1d3664e4ade92cacbb
parent 7ab48309eb1c52ed78f36444b9a4617d8c7b1824
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Tue Dec 23 04:23:28 -0800 2008 | |
| |
README.markdown | ||
| |
Rakefile | ||
| |
VERSION | ||
| |
clear_empty_attributes.gemspec | ||
| |
init.rb | Mon Feb 05 06:55:52 -0800 2007 | |
| |
lib/ | ||
| |
spec/ | ||
| |
tasks/ | Thu Jan 15 22:15:35 -0800 2009 |
README.markdown
Problem
When AR objects are saved, empty fields are saved as '' instead of nil.
- Complicates queries for empty fields (
WHERE field IS NULL OR field = '') - Makes the use of
unless field.blank?necessary (opposed to onlyif field) - Can lead to late-detected bugs because most of the time strings were
filled or ''and suddenly they arenil - Some validations do not support
:allow_blank=>true - Databases can handle
NULLbetter & faster than empty strings (especially when usingLIKE)
Solution
Defines an AR before_validation that sets empty Strings to nil.
Install
script/plugin install git://github.com/collectiveidea/clear_empty_attributes.git
OR
sudo gem install clear_empty_attributes -s http://gemcutter.org
Migration
When you are switching to clear_empty_attributes, run this task
to remove any '' strings/texts from your database.
rake db:clear_empty_attributes
(only works when checked out or installed as plugin)
Authors
Hereby placed under public domain, do what you want, just do not hold anybody accountable...


