Skip to content

Warning for nested module: associated module is not an Ecto schema #3803

@djthread

Description

@djthread

I noticed this issue seems to have been discussed before in #2209 from 2017, and indeed, I didn't get these warnings in Elixir 1.12, but it seems that upgrading to Elixir 1.13 has caused these warnings for me.

The reason I can't easily refactor to avoid this is because this warning is actually coming from code generated via macros in my Versioned library. (I could embark on some refactoring of the library if necessary, but if we get to that, I'd love some advice on what might work best.)

I dug into Ecto.Association.ensure_compiled/2 and noticed that env.context_modules only had the inner module when it seems the intent was for it to include the outer module, too?

Thank you so, so much, for any advice.

Environment

  • Elixir version (elixir -v): 1.13.0
  • Ecto version (mix deps): 3.7.1
  • Operating system: macOS 12.1

Current behavior

defmodule Thing do
  use Ecto.Schema

  schema "things" do
    field :name, :string
  end

  defmodule SubThing do
    use Ecto.Schema

    schema "sub_things" do
      field :name, :string
      belongs_to :thing, Thing
    end
  end
end

This code yields:

warning: invalid association `thing` in schema Thing.SubThing: associated module Thing is not an Ecto schema
  lib/ecto_test.ex:8: Thing.SubThing (module)

Expected behavior

No warning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions