multilang-hstore icon indicating copy to clipboard operation
multilang-hstore copied to clipboard

Can't assign nil to a multilang field

Open richyshredder opened this issue 10 years ago • 1 comments

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

richyshredder avatar Dec 04 '14 06:12 richyshredder

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:

  • Modify logic so it allows nulls
  • Update Reame

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

bithavoc avatar Dec 05 '14 02:12 bithavoc