Skip to content

nilify also json/jsonb values/columns? #54

@ClaudioFloreani

Description

@ClaudioFloreani

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions