Displays/assigns null when showing/editing empty object
sedubois opened this issue · comments
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:
2/ It is rendered as null
on edit view:
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:
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.