Skip to content

Incorrect inflection for param key of association ids #452

@laurenfackler

Description

@laurenfackler

For checkbox inputs of associations with unique pluralization requirements, e.g. specialty/specialties, ExAdmin incorrectly pluralizes the <association>_ids param key: specialtys.

In https://github.com/smpallen99/ex_admin/blob/master/lib/ex_admin/param_associations.ex#L34, if you replace

new_key =
  String.replace_suffix(key_as_string, "_ids", "s")
  |> String.to_atom()

with

key_as_string
  |> String.replace("_ids", "")
  |> Inflex.pluralize()
  |> String.to_atom()

it fixes the issue.

As a quick workaround, you can name the collection field so it takes the current pluralization logic, a simple prefix of s, into account. For example, instead of

inputs(:specialties, as: :check_boxes, collection: Repo.all(Specialty))

which will change the params key from specialty_ids to specialtys, you can do

inputs(:specialtie, as: :check_boxes, collection: Repo.all(Specialty))

which changes the params key from specialtie_ids to specialties, which is what's needed.

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