Hi all. Mysql allows to set multiple NULLs on columns with unique constraint, it''s normal SQL. Well, but when I try to submit some form, all unspecified values will be consodered as '''' (empty string) and (Mysql::Error: Duplicate entry occurs (((. How I can teach ActiveRecord to consider empty fields as NULL?
Julian ''Julik'' Tarkhanov
2006-Aug-05 00:26 UTC
[Rails] ActiveRecord, Mysql, NULL columns and uniqueness
On 5-aug-2006, at 5:02, zven wrote:> Hi all. > Mysql allows to set multiple NULLs on columns with unique constraint, > it''s normal SQL. Well, but when I try to submit some form, all > unspecified values will be consodered as '''' (empty string) and > (Mysql::Error: Duplicate entry occurs (((. How I can teach > ActiveRecord > to consider empty fields as NULL?It has not that much to do with SQL than with ActiveRecord, which doesn''t coerce empty strings to nil. Try this: http://julik.textdriven.com/svn/tools/rails_plugins/attribute_cleanup/ -- Julian ''Julik'' Tarkhanov please send all personal mail to me at julik.nl