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

Does not work with nested fields #4

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

Does not work with nested fields #4

sedubois opened this issue Oct 31, 2019 · 3 comments
Assignees

Comments

@sedubois
Copy link

This gem looks helpful to solve the issue described in codica2/administrate-field-jsonb#1, thanks!

However it does not seem to support nested fields. I have a Post dashboard configured as follows (schema was configured by globalize):

# app/dashboards/post_dashboard.rb
class PostDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    translations: NestedHasMany.with_options(class_name: "Post::Translation"),
    ...
  }.freeze
  ...
end

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

The aim is to apply deserialize_json_fields to the tags field of the post translation.

NB: NestedHasMany is a modification of Field::NestedHasMany to support namespaced models, as shown here.

There are two problems:

  • the README instructs to define deserialize_json_fields on the controller, but both Admin::Post::TranslationsController and Admin::PostsController will potentially need to handle the submission of tags (respectively either being a direct property of the resource associated to the controller, or as a property of the nested sub-resource through the has-many relation)
  • there is no way with the current syntax to instruct to deserialize the field in the nested resource (which is the scenario I need the most). The transformation should actually be applied not on tags, but on the form's translations_attributes value which looks like this:
{
  "0"=>{"id"=>"19", "_destroy"=>"false", "locale"=>"en", "tags"=>"[\"in english\"]", ...},
  "1"=>{"id"=>"20", "_destroy"=>"false", "locale"=>"fr", "tags"=>"[\"en français\"]", ...}
}
@SleeplessByte
Copy link
Member

SleeplessByte commented Nov 2, 2019

I think I understand the issue. Basically I don't interpret the nested fields correctly (because it uses field_attributes instead of field)?

there is no way with the current syntax to instruct to deserialize the field in the nested resource (which is the scenario I need the most). The transformation should actually be applied not on tags, but on the form's translations_attributes value which looks like this:

So this is what you really need right?

I'll see what I can do. It might be a while, but I don't mind you nagging me if I seem to have forgotten about it.

@sedubois
Copy link
Author

sedubois commented Nov 3, 2019

Basically I don't interpret the nested fields correctly (because it uses field_attributes instead of field)?

Correct.

So this is what you really need right?

Yes that's the blocking point; and also there should also be a way to configure this deserialization behaviour in a single place instead of in two different controllers (Admin::PostsController and Admin::Post::TranslationsController).

@SleeplessByte
Copy link
Member

SleeplessByte commented Nov 3, 2019 via email

@SleeplessByte SleeplessByte self-assigned this Mar 4, 2020
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

2 participants