Skip to content

Support preloading associations in embedded schemas from the parent schema #3890

Closed

Description

@nallwhy

Current behavior

defmodule Child do
  use Ecto.Schema

  schema "children" do
  end
end

defmodule Parent do
  use Ecto.Schema

  schema "parents" do
    embeds_many(:details, Detail, primary_key: false, on_replace: :delete) do
      belongs_to(:child, Child)
    end
  end
end

Parent
|> preload(details: :child)
|> Repo.all()
** (ArgumentError) schema Parent does not have association :details
...

By #3368, Ecto.Repo.c:preload/3 works from the embedded schema, but not from the parent schema yet.

Activity

  1. josevalim commented on May 1, 2022

    @josevalim
    Member

    Good find. We should probably "allow" embeds in preload as long as they are loading an association inside.

  2. josevalim commented on May 1, 2022

    @josevalim
    Member

    A pull request to address this is welcome!

  3. Sleepful commented on Jul 27, 2022

    @Sleepful
    Contributor

    Working on a pull request for this

  4. wakeless commented on Aug 9, 2022

    @wakeless

    Thanks for doing this @Sleepful so nice.

    I've been working on this as well and hadn't seen you'd been working along on it. My approach is a little more naive but thought I'd link it here in case there's something useful. master...wakeless:ecto:allow-preloading-within-nested-schemas

  5. greg-rychlewski commented on Sep 11, 2022

    @greg-rychlewski
    Member

    Closed by #3967

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions