Skip to content

Commit

Permalink
Update Multi tenancy with foreign keys.md (#3462)
Browse files Browse the repository at this point in the history
  • Loading branch information
LostKobrakai committed Oct 27, 2020
1 parent b02c13c commit 11ced85
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions guides/howtos/Multi tenancy with foreign keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ defmodule MyApp.Comment do
schema "comments" do
field :body
field :org_id, :integer
belongs :post, MyApp.Post
belongs_to :post, MyApp.Post
timestamps()
end
end
Expand Down Expand Up @@ -185,7 +185,7 @@ create table(:comments) do

# Instead define a composite foreign key
add :post_id,
references(:posts, with: [org_id: org_id]),
references(:posts, with: [org_id: :org_id]),
null: false

timestamps()
Expand All @@ -199,7 +199,7 @@ Given composite foreign keys require the references keys to be unique, we also d
If you are using PostgreSQL and you want to tighten these guarantees even further, you can pass the `match: :full` option to `references`:

```elixir
references(:posts, with: [org_id: org_id], match: :full)
references(:posts, with: [org_id: :org_id], match: :full)
```

which will help enforce none of the columns in the foreign key can be nil.
Expand All @@ -216,11 +216,11 @@ create table(:comments) do
add :org_id, :integer, null: false

add :post_id,
references(:posts, with: [org_id: org_id]),
references(:posts, with: [org_id: :org_id]),
null: false

add :user_id,
references(:users, with: [org_id: org_id]),
references(:users, with: [org_id: :org_id]),
null: false

timestamps()
Expand Down

0 comments on commit 11ced85

Please sign in to comment.