polypush135
In short this was what I tried to do.
from(q in query,
join:
va in ^from(va in VideoAnalysis,
where: va.id == ^video_id,
limit: 1,
order_by: [desc: :inserted_at]
),
join: v in assoc(va, :video),
where: v.id == ^video_id
)
But soon found that …
** (Ecto.QueryError) ....query.ex:108: queries in joins can only have `where` conditions in query:
from c in Clip,
join: v0 in ^#Ecto.Query<from v in VideoAnalysis, where: v.id == ^7275, order_by: [desc: v.inserted_at], limit: 1>,
join: v1 in assoc(v0, :video),
where: v1.id == ^7275
select: c
trying to figure out how I can query for all the records of a thing through an intermediate record.
IE say I have a VideoAnalysis record that belongs_to a video and has many clips.
How can I query for all the clips of a video analysis if all I know if the video id?
But there is a catch in my case join: video_analysis in assoc(c, :video_analysis), would return multiple records.
Q: How could I make it to where I can limit it to only the newest based on inserted at for VideoAnalysis
in short I’m trying to do all this in the Ecto Query with just one query
if that is even possible
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
idi527
Have you tried using
subquery/2?Not sure if it would even work …
polypush135
I got that far, though I though it was the same thing I was already doing. That said it does not raise an error, though on the other hand it does not return expected results.
idi527
What’s
video_id, why is it in bothwhereclauses?peerreynders
How is that a catch. Given that a video can have multiple clips you would expect the same video analysis to appear with each clip that belongs to the video.
I’m assuming
polypush135
Sorry trial and error copy and pasting
The idea is that I only know of a video but I want all the clips found on the
newestvideo_analysis which belongs to the video. the issue is that there are manyvideo_analysisthat belong to a given videoidi527
What about a subquery in a lateral join then?Ah, it’s not necessary actually. What about this?peerreynders
So you want each clip no more than once even if it is referenced by multiple video analyses (for the same video).
A subquery using
distinct/3on the video id could work.polypush135
the stack is like so.
VideoAnalysis:
Video:
Clip:
I want all the clips found on the
newestVideoAnalysis that belongs to video x.LostKobrakai
peerreynders
You are starting with a
video_id- so ultimately the can only be 1 or 0 distinctvideo_ids- 0 being the case when you can’t find any VideoAnalyses, 1 if there is one or more Video Analyses.So it seems to boil down to
So your query could be phrased as:
video_idif there is at least one Video Analysis (… which seems odd)Something along the lines of
nlatest Video Analysesvideo_idssounds much more likely
Never mind, so it was