Closed tadasajon closed 2 years ago
@tadasajon have you tried removing _build
?
The library simply uses all modules which have __schema__/1
function https://github.com/fuelen/ecto_erd/blob/1dd8b9a4f85dd10f435f3cbf779cd6f95b375b5e/lib/ecto/erd/schema_modules.ex#L4-L16
Thanks much for responding.
I have a file in my codebase that looks like this:
defmodule Quizdrill.Accounts.SpecialUser do
use Ecto.Schema
import Ecto.Changeset
schema "special_users" do
field :special_id, :integer
field :first_name, :string
field :last_name, :string
field :username, :string
timestamps()
end
@doc false
def changeset(special_user, attrs) do
special_user
|> cast(attrs, [:special_id, :first_name, :last_name, :username])
|> validate_required([:special_id])
|> unique_constraint(:special_id)
end
end
I am assume that because I have the line use Ecto.Schema
that there will be a __schema__/1
function. Am I incorrect?
Yes, use Ecto.Schema
defines __schema__/1
function.
Check your other modules, which have a line like belongs_to :special_user, SpecialUser
. Seems like one of those modules references to the module which doesn't exist. Perhaps you don't have declared alias for Quizdrill.Accounts.SpecialUser
in one of those modules.
Hey @tadasajon Any luck?
They seem to have forgotten this issue, but fortunately I was able to replicate. I locally patched my copy to give debugging output (IO.inspect) and was able to get it to run by commenting out things that didn't refer to schemas.
However, the reason some of ours did this was because in bonfire, we have a pluggability thing going on and it's convenient for us to be able to list relationships that might not exist and just not use them if they don't.
So I wrapped a few function bodies in if function_exported?(...)
with a Logger.warn branch when the module was not a schema or could not be found, offering a little debug information to help the user in case they did actually want to do something about them.
Unfortunately I did it on the copy in deps
because i'd already hacked it with debugging output before, so I figured I'd ask before replicating the work to a git clone: is this something you'd consider accepting a PR for?
@jjl Hello Yes, PR is welcome :)
Resolved in #13
I just installed this library and tried to run
mix ecto.gen.erd
. It immediately crashed with this error:I am able to create
SpecialUser
s in my app when I am using it and my app works fine in this regard, so I am not sure why this library is complaining.