Add two foreign key columns that reference the same table

Hey @axelclark, have you figured this out yet? I’m doing a similar type thing where I have an Admin class and a CaseStudy class. I would like my case_studies to belong to admins through two different columns, [:created_by_id, :updated_by_id].

I keep getting and error though. ** (ArgumentError) field/association :case_studies is already set on schema

Here’s some codes.

defmodule MyApp.Admin do
  field :name, :string

  has_many :case_studies, CaseStudy, foreign_key: :created_by_id
  has_many :case_studies, CaseStudy, foreign_key: :updated_by_id
end

defmodule MyApp.CaseStudy do
  field :title, :string

  belongs_to :admin, MyApp.Admin, foriegn_key: :created_by_id
  belongs_to :admin, MyApp.Admin, foriegn_key: :updated_by_id
end