Skip to content

Commit 34a5e05

Browse files
soundmonsterLeo B
authored and
Leo B
committed
Add associations with composite primary keys
* BelongsTo * HasMany * ManyToMany
1 parent c8b9c57 commit 34a5e05

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Diff for: integration_test/support/migration.exs

+22
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ defmodule Ecto.Integration.Migration do
2727
add :intensity, :float
2828
add :author_id, :integer
2929
add :posted, :date
30+
add :composite_a, :integer
31+
add :composite_b, :integer
3032
timestamps(null: true)
3133
end
3234

@@ -108,6 +110,26 @@ defmodule Ecto.Integration.Migration do
108110
add :name, :string
109111
end
110112

113+
create table(:composite_pk_composite_pk, primary_key: false) do
114+
add :b_1, :integer
115+
add :a_1, references(:composite_pk, column: :a, with: [b_1: :b], type: :integer)
116+
add :b_2, :integer
117+
add :a_2, references(:composite_pk, column: :a, with: [b_2: :b], type: :integer)
118+
end
119+
120+
121+
alter table(:posts) do
122+
modify :composite_a, references(:composite_pk, column: :a, with: [composite_b: :b], type: :integer)
123+
end
124+
125+
create table(:posts_composite_pk) do
126+
add :post_id, references(:posts), primary_key: true
127+
add :composite_a, references(:composite_pk, column: :a, with: [composite_b: :b], type: :integer), primary_key: true
128+
add :composite_b, :integer, primary_key: true
129+
end
130+
131+
create unique_index(:posts_composite_pk, [:post_id, :composite_a, :composite_b])
132+
111133
create table(:corrupted_pk, primary_key: false) do
112134
add :a, :string
113135
end

0 commit comments

Comments
 (0)