Arsenalist
Sorting by a join field in a query with Flop not working
I’m sorting by a join field and it’s throwing an error. Here’s the query being executed:
from(p in Product,
left_join: variants in assoc(p, :variants), as: :variants,
left_join: venue_arrangement in assoc(p, :venue_arrangement)
preload: [
variants: variants
]
)
Here are the schemas:
defmodule Amplify.Models.Product do
use Amplify.MedusaSchema
@derive {
Flop.Schema,
filterable: [:showtimes],
sortable: [:showtimes],
adapter_opts: [
join_fields: [
showtimes: [
binding: :variants,
field: :starts_at_utc,
path: [:variants, :utc_datetime]
]
]
]
}
schema "product" do
field :title, :string
has_many :variants, Amplify.Models.ProductVariant
end
end
defmodule Amplify.Models.ProductVariant do
use Amplify.MedusaSchema
schema "product_variant" do
belongs_to :product, Amplify.Models.Product
field :thumbnail, :string
field :starts_at_utc, :utc_datetime
end
end
When I pass in ["showtimes"] as order_directions to flop params and call like this:
Flop.validate_and_run(query, flop_params)
I get:
** (Postgrex.Error) ERROR 42703 (undefined_column) column p0.showtimes does not exist
Marked As Solved
woylie
You’ll need to pass the schema module. Flop doesn’t infer the schema automatically.
Flop.validate_and_run(query, flop_params, for: Amplify.Models.Product)
1
Popular in Questions
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir? ...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Hi all,
Trying to get some more clarity over utc_datetime and naive_datetime for Ecto:
https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”:
14:57:30.512 [warn] ...
New
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
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Hi all,
I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I'm trying to use Postg...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Other popular topics
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
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
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New







