bithavoc / multilang-hstore

Multilang is a small library for translating database values for Rails 4 and Postgresql hstore
MIT License
41 stars 18 forks source link

Can't assign nil to a multilang field #3

Open richyshredder opened 9 years ago

richyshredder commented 9 years ago

I've noticed some my rspec tests failed because new instance had empty string "" instead of nil:

class CustomField < ActiveRecord::Base
  multilang :name
  ...
end
c = CustomField.new
 => #<CustomField...

c.name
 => ""

c.name = {}
 => {} 

c.name
 => "" 

c.name = {I18n.locale => nil}
 => {:ru=>nil}

c.name
 => "" 

What is the reason of such behavior? PostgreSQL seems to work with NULL values in hstore: http://www.postgresql.org/docs/9.0/static/hstore.html

bithavoc commented 9 years ago

Hi,

this is legacy behavior from the initial gem.

It makes sense, it should be nullable. Can you come up with a pull request?

This would be the goal:

I'll make a major bump version adding instructions in the readme warning of this breaking change.