dirksierd

dirksierd

Preload associated record through embedded schema

Hi there!

I have a schema looking something like this:

defmodule Shop.Order do
  schema "orders" do
    embeds_many :lines, Line
  end
end
defmodule Shop.Line do
  embedded_schema do
    belongs_to :product, Product
  end
end

Now I’m trying to preload the products in the embedded Line-schema, but I get an error-message:

query = from(o in Order, limit: 1, preload: [lines: :product])
Repo.one(query)

# => schema Shop.Order does not have association :lines

That sort-of makes sense, I suppose, but is there a way around this?

First Post!

dirksierd

dirksierd

Migrated away from embedded-schema’s to regular association with lines-table. Would still be interested to know if it’s possible to do it with embedded_schema though.

Last Post!

LostKobrakai

LostKobrakai

Afaik belongs_to is now supported in ecto, even though it’s not backed by a foreign key constraint in the db.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
stefanchrobot
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
fireproofsocks
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
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

Other popular topics Top

minhajuddin
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
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement