rubiety/nilify_blanks — pull request #5 by pjungwir (2012-07-16 04:55:46+00:00)
Title: Allow _id columns if they are specified in the :only parameter

The current code automatically filters out primary keys, columns ending with _id or _count, and the column to track the type in a polymorphic table, because it only operates on columns that are within the array returned from Rails' `content_columns` method. But sometimes you might have a String column that ends with _id that is not a foreign key, but is used to track something else (e.g. an identifier from a remote system), and you want to use it with nilify_blanks. It seems to me that if you specify a column in the nilify_blanks `:only` parameter, you are clearly indicating you want to convert blanks to nils in that column, even if it ends with _id or is otherwise not included by `content_columns`. So this patch only queries `content_columns` if you have not given an `:only` parameter. If you give an `:only` parameter, we assume you know what you are doing and really mean for nilify_blanks to operate on all the columns you listed.