polypush135
(Ecto.Query.CastError) value `"some uuid"` in `where` cannot be cast to type :id in query:
just trying to preload an association
p = Pix |> Repo.get("074a1581-fd36-49e7-a756-03d30f378312")
%PolymorphicProductions.Social.Pix{
__meta__: #Ecto.Schema.Metadata<:loaded, "pics">,
asset: "https://d1sv288qkuffrb.cloudfront.net/polymorphic-productions/photos/37409259750_420cebcc8a_b.jpg",
asset_preview: "https://d1sv288qkuffrb.cloudfront.net/polymorphic-productions/photos/preview/37409259750_420cebcc8a_b.jpg",
comments: #Ecto.Association.NotLoaded<association :comments is not loaded>,
description: "asdf",
id: "074a1581-fd36-49e7-a756-03d30f378312",
inserted_at: ~N[2018-11-04 18:58:03.347422],
photo: nil,
updated_at: ~N[2018-11-04 18:58:03.347444]
}
iex(10)> p |> Repo.preload([:comments])
** (Ecto.Query.CastError) deps/ecto/lib/ecto/association.ex:516: value `"074a1581-fd36-49e7-a756-03d30f378312"` in `where` cannot be cast to type :id in query:
from c in PolymorphicProductions.Social.Comment,
where: c.pix_id == ^"074a1581-fd36-49e7-a756-03d30f378312",
order_by: [asc: c.pix_id],
select: {c.pix_id, c}
(elixir) lib/enum.ex:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
(elixir) lib/enum.ex:1418: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
(elixir) lib/enum.ex:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
(ecto) lib/ecto/repo/queryable.ex:124: Ecto.Repo.Queryable.execute/5
(ecto) lib/ecto/repo/queryable.ex:37: Ecto.Repo.Queryable.all/4
(elixir) lib/enum.ex:1314: Enum."-map/2-lists^map/1-0-"/2
Any ideas what I’m doing wrong?
Marked As Solved
polypush135
The solution was to set the type not only on the schema but also on the belongs_to.
belongs_to(:pix, Pix, type: :binary_id)
I would have assumed that setting the schema’s primary key type would have been enough as per the docs say.
@foreign_key_type- configures the default foreign key type used bybelongs_toassociations. Defaults to:id;
7
Also Liked
NobbZ
I have no clue and I’m not using ecto, also I have not slept for 36+ hours now, but I’m pretty sure that someone will ask anyway, can you show your schemas and migrations involved?
4
polypush135
I think this was a case of miss reading the docs or possibly a bug on ecto.
I’ve since filed a bug for clarification since either the docs are miss leading or there is a bug.
1
Popular in Questions
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
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
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
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
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
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 am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Other popular topics
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode.
The solution seems to be, in a hyphena...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
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
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition)
It’s been a while since we first asked this, I...
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
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
New
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
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
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









