Skip to content

Commit

Permalink
Add associations with composite primary keys
Browse files Browse the repository at this point in the history
* BelongsTo
* HasMany
* ManyToMany
  • Loading branch information
soundmonster authored and Leo B committed Apr 6, 2022
1 parent 8727a74 commit 53a3395
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions integration_test/support/migration.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ defmodule Ecto.Integration.Migration do
add :intensity, :float
add :author_id, :integer
add :posted, :date
add :composite_a, :integer
add :composite_b, :integer
timestamps(null: true)
end

Expand Down Expand Up @@ -108,6 +110,26 @@ defmodule Ecto.Integration.Migration do
add :name, :string
end

create table(:composite_pk_composite_pk, primary_key: false) do
add :b_1, :integer
add :a_1, references(:composite_pk, column: :a, with: [b_1: :b], type: :integer)
add :b_2, :integer
add :a_2, references(:composite_pk, column: :a, with: [b_2: :b], type: :integer)
end


alter table(:posts) do
modify :composite_a, references(:composite_pk, column: :a, with: [composite_b: :b], type: :integer)
end

create table(:posts_composite_pk) do
add :post_id, references(:posts), primary_key: true
add :composite_a, references(:composite_pk, column: :a, with: [composite_b: :b], type: :integer), primary_key: true
add :composite_b, :integer, primary_key: true
end

create unique_index(:posts_composite_pk, [:post_id, :composite_a, :composite_b])

create table(:corrupted_pk, primary_key: false) do
add :a, :string
end
Expand Down

0 comments on commit 53a3395

Please sign in to comment.