I have two schemas Todo
and TodoAssignment
. TodoAssignment
keeps track of a log of users a given todo has been assigned to.
I’m getting a warning on my TodoAssignment
module stating:
invalid association
todo
in schema Delega.TodoAssignment: associated schema Delega.Todo does not exist
The schema definitely exists and all the code seems to work fine. I’m seeing this on two tables that reference my Todo
schema.
Todo Schema
defmodule Delega.Todo do
use Ecto.Schema
import Ecto.Changeset
alias Delega.{Todo, Repo, TodoAssignment}
@primary_key {:todo_id, :id, autogenerate: true}
schema "todo" do
belongs_to :team, Delega.Team, references: :team_id, type: :string
has_many :channels, Delega.TodoChannel, foreign_key: :todo_id
field :created_user_id, :string
has_one :created_user, Delega.User, references: :created_user_id, foreign_key: :user_id
has_many :assignments, Delega.TodoAssignment, foreign_key: :todo_id
field :todo, :string
field :status, :string
end
end
TodoAssignment Schema
defmodule Delega.TodoAssignment do
use Ecto.Schema
alias Delega.Todo
@primary_key {:todo_assignment_id, :id, autogenerate: true}
schema "todo_assignment" do
field :assigned_to_user_id, :string
field :assigned_by_user_id, :string
belongs_to :todo, Todo, references: :todo_id, foreign_key: :todo_id
has_one :assigned_to_user, Delega.User,
references: :assigned_to_user_id,
foreign_key: :user_id
has_one :assigned_by_user, Delega.User,
references: :assigned_by_user_id,
foreign_key: :user_id
field :created_at, :utc_datetime_usec
field :updated_at, :utc_datetime_usec
end
end
It seems like regardless of whether I use references
or foreign_key
I get this warning. I also get it on my TodoChannel
table.
Why am I getting these warnings?