Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sedubois opened this issue Oct 31, 2019 · 0 comments
Open

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

sedubois opened this issue Oct 31, 2019 · 0 comments

Comments

@sedubois
Copy link

sedubois commented Oct 31, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant