I’ve tired to use foreign key as primary key.
ex)
create table(:users) do
end
create table(:traders, primary_key: false) do
add :id, references(:users, type: :integer), primary_key: true
end
create table(:dum) do
add :trader_id, references(:traders), null: false
end
defmodule Trader do
...
schema "traders"
belongs_to :user, User, foreign_key: :id, primary_key: true
has_many :dums, Dum
end
end
And it fails with
** (ArgumentError) argument error
lib/ecto/association.ex:498: Ecto.Association.Has.get_ref/3
lib/ecto/association.ex:448: Ecto.Association.Has.struct/3
lib/ecto/schema.ex:1399: Ecto.Schema.association/5
lib/ecto/schema.ex:1556: Ecto.Schema.__has_many__/4
lib/trader.ex:11: (module)
Can I use foreign key as primary key with Ecto?