Cannot find the right binding when sorting by fragment in many_to_many

has_many :semantically_similar, __MODULE__ do
no_attributes? true

sort [
calc(
fragment(
"? <=> ?",
utterance.vectorized_content,
parent(utterance.vectorized_content)
)
)
]

limit 3
end
has_many :semantically_similar, __MODULE__ do
no_attributes? true

sort [
calc(
fragment(
"? <=> ?",
utterance.vectorized_content,
parent(utterance.vectorized_content)
)
)
]

limit 3
end
it seems like this should be possible: https://hexdocs.pm/ash/expressions.html#many-to-many-relationships The error: (Ecto.SubQueryError) the following exception happened when compiling a subquery.\n\n (Ecto.QueryError) could not find named binding parent_as(1) in query"
13 Replies
ZachDaniel
ZachDaniel•2mo ago
make sure to upgrade ash, ash_postgres and ash_sql fully there was a bug sort of like this
rtorresware
rtorreswareOP•2mo ago
checking same problem on latest funnily enough, this works:
filter expr(
fragment(
"? <=> ? < .15",
utterance.vectorized_content,
parent(utterance.vectorized_content)
) and
translation.language == parent(translation.language)
)
filter expr(
fragment(
"? <=> ? < .15",
utterance.vectorized_content,
parent(utterance.vectorized_content)
) and
translation.language == parent(translation.language)
)
ZachDaniel
ZachDaniel•2mo ago
oh, interesting it may be something we fixed for filteirng but not for sorting 😢 Will need to fix @rtorresware if you can also add a repro test to ash_postgres that would be great 🙂
rtorresware
rtorreswareOP•2mo ago
I’ll check the previous issue and see if I can fix
rtorresware
rtorreswareOP•2mo ago
@Zach Daniel would this be the issue you had in mind? https://github.com/ash-project/ash_postgres/issues/287#issue-2299360409
GitHub
parent does not work from within an aggregate filter · Issue #287...
When attempting to use parent from within an aggregates filter the following error is thrown Unsupported expression in Elixir.AshPostgres.SqlImplementation query: %{attribute: :queue_id, resource: ...
rtorresware
rtorreswareOP•2mo ago
nvm I don't think it is
ZachDaniel
ZachDaniel•2mo ago
It looks like the one I was thinking of yeah but it may be unrelated 🤔 there is work that we do to get the paths that we need to join on the parent query for and wherever that is we're probably missing it in the sort somehow
rtorresware
rtorreswareOP•2mo ago
is this a good repro? a fork of the ash_postgres repo with added tests that fail. https://github.com/rtorresware/ash_postgres/commit/fe590d84d406b592064a2844b0b45e0a422d9ba6
GitHub
add a test for default sort referencing parent field in many_to_man...
…relationship with no_attributes? true
rtorresware
rtorreswareOP•2mo ago
I tried to fix but it all goes over my head.
ZachDaniel
ZachDaniel•2mo ago
Yep! Can you PR the failing test?
rtorresware
rtorreswareOP•2mo ago
sure, on it
rtorresware
rtorreswareOP•2mo ago
GitHub
add a test for default sort referencing parent field in many_to_man...
…relationship with no_attributes? true Contributor checklist Leave anything that you believe does not apply unchecked. I accept the AI Policy, or AI was not used in the creation of this PR. Bug ...
rtorresware
rtorreswareOP•2mo ago
oops I made the test .ex and not .exs that's why it did not run. Here's the PR to fix: https://github.com/ash-project/ash_postgres/pull/609/files
GitHub
rename test file so it matches pattern by rtorresware · Pull Reque...
Contributor checklist Leave anything that you believe does not apply unchecked. I accept the AI Policy, or AI was not used in the creation of this PR. Bug fixes include regression tests Chores ...

Did you find this page helpful?