Skip to content

Displays/assigns null when showing/editing empty objectΒ #9

@sedubois

Description

@sedubois

There are 3 related issues when a JSONB field contains a non-null but empty object ([] or {}).

1/ It is rendered as - on show view:
Screenshot 2019-10-31 at 14 01 59
2/ It is rendered as null on edit view:
Screenshot 2019-10-31 at 14 02 06
3/ When saving the form, even though I have not modified anything, instead of keeping the original value it tries to assign the value null, which breaks my non-null DB constraint and throws an error.

Instead, it should render the empty array or empty object, as below:
Screenshot 2019-10-31 at 14 05 28
Screenshot 2019-10-31 at 14 08 33

My code:

# db/schema.rb
  create_table "post_translations", force: :cascade do |t|
    ...
    t.jsonb "tags", default: [], null: false
end

# app/dashboards/post/translation_dashboard.rb
class Post::TranslationDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    ...
    tags: Field::JSONB,
    ...
  }.freeze
  ...
end

(+ using workaround described in #1 (comment))

Using administrate-field-jsonb 0.4.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions