srcoulombe
This might be somewhat related to Sorting by a join field in a query with Flop not working, but I wasn’t able to follow the author’s solution
Context
I have two schemas: one for assets and another for issues.
Assets
# asset.ex
@derive {
Flop.Schema,
filterable: [:name],
sortable: [:updated_at, :ongoing_issues_count],
adapter_opts: [
join_fields: [
ongoing_issues_count: [
binding: :ongoing_issues_count,
field: :count,
ecto_type: :integer
]
]
]
}
schema "assets" do
field :name, :string
has_many :issues, Issue
end
Issues
# issue.ex schema "issues" do field :title, :string field :description, :string field :status, Ecto.Enum, values: @supported_statuses, default: :ongoing end
Intentions
I’m trying to do two things within the Flop table that lists all my assets:
- show how many issues with
status==:ongoingare associated to eachasset, and - allow users to sort the table in increasing/decreasing order based on how many
issues withstatus==:ongoingare associated to eachasset
I was able to accomplish 1. by defining the @derive Flop.Schema in the “assets.ex” file:

I’m struggling to understand why I can’t sort by the ongoing_issues_count join field though ![]()
Here’s the list_assets function I’m currently working with:
def list_assets(params) do
ongoing_issues_count_query =
Issue
|> where([issue], parent_as(:asset).id == issue.asset_id)
|> where([issue], issue.status == :ongoing)
|> select([issue], %{count: count(issue)})
query =
Asset
|> from(as: :asset)
|> join(
:left_lateral,
[asset],
ongoing_issues_count in subquery(ongoing_issues_count_query),
as: :ongoing_issues_count
)
|> select([asset, ongoing_issues_count], %{
asset: asset,
ongoing_issues_count: ongoing_issues_count
})
Flop.validate_and_run(query, params, for: Asset)
end
Thanks in advance to anyone who reads this!
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!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
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
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
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
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
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
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 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
srcoulombe
figured it out - i had one obvious bug, and one smaller mistake.
the smaller mistake was with how i had constructed the
ongoing_issues_count_query. I ended up converting it to:with the outer query being:
the
coalesceis there to ensure thatnullvalues are converted to0.the bigger bug was that my Flop table had
instead of