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

accept value_fn for {:array, _} field #321

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

onizuka8
Copy link

This change will allow to define a :value_fn for any {:array, _} field. I use it as work-around for many_to_many associations. What I do is adding the field in the Kaffy.MyModelAdmin.form_fields/1

def form_fields(schema) do 
    Kaffy.ResourceSchema.form_fields(schema)
    |> Keyword.put(:associated_entities, %{
      type: {:array, :integer},
      value_fn: fn model ->
        Repo.preload(model, [:other_entities])
        |> Map.get(:other_entities)
        |> Enum.map(& &1.id)
      end,
      values_fn: fn _, _ ->
        Repo.all(Models.Entity)
        |> Enum.map(&{&1.name, &1.id})
      end
    })
end

@ghenry
Copy link
Collaborator

ghenry commented Dec 11, 2024

Hi,

Thanks for your contribution!

Is this still required and works on the latest version?

Gavin.

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

Successfully merging this pull request may close these issues.

3 participants