私はそれを過度に複雑にしなければなりませんが、私は簡単な問題の周りに頭を抱えて苦労しています。Ecto associations has_one belongs_to
は、私は2つのテーブルglobal_users
とlocal_users
持って言う:プログラム
create table(:global_users, primary_key: false) do
add :id, :integer, primary_key: true
add :local_user_id, references(:local_users)
...
end
create table(:local_users, primary_key: false) do
add :id, :integer, primary_key: true
add :global_user_id, references(:global_users)
...
end
@primary_key {:id, :integer, autogenerate: false}
schema "global_users" do
has_one :local_user, Local.User
...
end
@primary_key {:id, :integer, autogenerate: false}
schema "local_users" do
belongs_to :global_user, Global.User
...
end
を、私は最初、私は事実の後に2を関連付ける必要があり、LOCAL_USERを作成し、その後、global_userを作成します。
例えば、与えられた既存の有効なglobal_user
および既存の、local_user
有効な、私は関連付けるだろうか、既存のglobal_user
からlocal_user
を既存の?
has_one
を追加すると、外部キー自体にアクセスできなくなります(更新するには、%Global.User{:local_user_id}
はありません)。
また、私はこれが簡単であると知っています。私は確かに何かを明らかにしていないと確信しています。
ありがとうございます!