rbino

rbino

Ash Core Team

Error when using :on_lookup for many_to_many sorted using expr_sort

This is a followup on my previous question, I’ll paste here the relevant part:

   many_to_many :dishes, Dish do
      through DailyMenuDish
      join_relationship :daily_menu_dishes

      sort [Ash.Sort.expr_sort(parent(daily_menu_dishes.position))]

      source_attribute_on_join_resource :daily_menu_id
      destination_attribute_on_join_resource :dish_id
    end

I had this relationship and all was well if I just wanted to create it and display it in order using the position attribute on the join resource (see previous post).

Now I also wanted to update the dishes in the menu (to be precise, I transformed the create to be an upsert) and I’ve found the correct options to do so using manage_relationship but they work only if I comment out the sort option.

If I don’t, it fails with:

* ** (KeyError) key :parent_bindings not found in: %{
  sort: [
    {#Ash.Resource.Calculation.Expression<[expr: parent(daily_menu_dishes.position)]>,
     :asc}
  ],
  context: %{
    private: %{actor: nil, authorize?: false, in_before_action?: true},
    action: %Ash.Resource.Actions.Read{
      arguments: [],
      description: nil,
      filter: nil,
      get_by: [],
      get?: false,
      manual: nil,
      metadata: [],
      modify_query: nil,
      name: :read,
      pagination: false,
      preparations: [],
      primary?: true,
      touches_resources: [],
      transaction?: false,
      type: :read
    },
    actor: nil,
    authorize?: false,
    accessing_from: %{name: :dishes, source: MyApp.MenuManagement.DailyMenu},
    query_opts: [
      verbose?: false,
      actor: nil,
      authorize?: false,
      page: nil,
      return_query?: false
    ],
    initial_limit: 1,
    initial_offset: 0,
    page_opts: nil,
    initial_query: #Ash.Query<
      resource: MyApp.MenuManagement.Dish,
      filter: #Ash.Filter<name == "baz">,
      sort: [
        {#Ash.Resource.Calculation.Expression<[expr: parent(daily_menu_dishes.position)]>,
         :asc}
      ],
      limit: 1
    >,
    filter_requests: []
  },
  bindings: %{
    0 => %{type: :root, path: [], source: MyApp.MenuManagement.Dish}
  },
  resource: MyApp.MenuManagement.Dish,
  current: 1,
  calculations: %{},
  aggregate_defs: %{},
  in_group?: false,
  current_aggregate_name: :aggregate_0,
  aggregate_names: %{},
  parent_resources: []
}    at dishes, 2

    (ash 2.17.3) lib/ash/api/api.ex:2324: Ash.Api.unwrap_or_raise!/3
    iex:41: (file)

I wasn’t sure where to open an issue because on_lookup is from Ash core, while the :parent_binding error comes from Ash Postgres, let me know if it helps if I do it and if I need to provide some more information.

Marked As Solved

rbino

rbino

Ash Core Team

Your commit in main fixed this, thanks!

Relevant commit for posterity:
https://github.com/ash-project/ash/commit/432d65a00320bb196a3b8cf7bb1ed91657925b35

Where Next?

Popular in Questions Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: &lt;h1&gt;Create Post&lt;/h1&gt; &lt;%= ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New

Other popular topics Top

New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New

We're in Beta

About us Mission Statement