rbino
Ash Core Team
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.
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
Hello,
I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 7 of 7 Posts
zachdaniel
NGL I don’t think I considered the case of using
parentin a relationship sort like that. Mind opening an issue onAshPostgres?zachdaniel
If you could PR a failing test that would be awesome too
I’ve got a few irons in the fire and a failing test would save me lots of time!
rbino
I’ve opened the issue and submitted a PR reproducing the failure
zachdaniel
So, the issue here is actually pretty interesting. The basic issue is that we use the
The only thing I can think to do is to ignore filters/sorts with
sortand thefilterof a relationship to lookup potential matches, and if there is aparentreference then it doesn’t really make sense…parentreferences when managing relationships.rbino
I’m not sure about filter, but I think ignoring the sort shouldn’t affect the result of
manage_relationship, or is the order relevant?zachdaniel
The order could theoretically be relevant. But in this case, it makes sense that we can’t apply the
filterorsortif they referenceparent, because we are looking up some not currently related thing.rbino
Your commit in
mainfixed this, thanks!Relevant commit for posterity:
https://github.com/ash-project/ash/commit/432d65a00320bb196a3b8cf7bb1ed91657925b35