nilify_blanks icon indicating copy to clipboard operation
nilify_blanks copied to clipboard

nilify also json/jsonb values/columns?

Open ClaudioFloreani opened this issue 2 years ago • 0 comments

In my models I use to set a callback to nilify blank json/jsonb values (and the whole column if it's just empty), in the following way:

before_save :nilify_blank_stored_attributes

  def nilify_blank_stored_attributes
    self.class.stored_attributes.keys.each do |stored_attribute|
      send(stored_attribute).delete_if{|k,v| v.blank?}
      send(stored_attribute.to_s.concat('=').intern, nil) if send(stored_attribute).empty?
    end
  end

How about adding this feature?

ClaudioFloreani avatar Nov 18 '21 17:11 ClaudioFloreani