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?

2 Likes

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.