| id | user_id | title |
|---|---|---|
| 1 | 1 | 初めての投稿 |
| 2 | 1 | 2つ目の投稿 |
| 3 | 2 | 佐藤の投稿 |
| id | name | team_id |
|---|---|---|
| 1 | 田中 | 1 ← 1つだけ |
| 2 | 佐藤 | 2 |
| user_id | team_id |
|---|---|
| 1 (田中) | 1 (開発) |
| 1 (田中) | 2 (デザイン) |
| 2 (佐藤) | 1 (開発) |
| user_id | team_id | role | joined_at |
|---|---|---|---|
| 1 | 1 | admin | 2025-01-10 |
| 2 | 1 | member | 2025-02-15 |
| id | title | status |
|---|---|---|
| 1 | 初めての投稿 | published |
| 2 | 書きかけの記事 | draft |
| 3 | 一時停止中 | suspended |
| id | message | read_at |
|---|---|---|
| 1 | 新着メッセージ | NULL |
| 2 | 承認されました | 2025-05-30 10:00 |
| id | name | deleted_at |
|---|---|---|
| 1 | 田中 | NULL(有効) |
| 2 | 佐藤 | 2025-05-01 |
| id | tags |
|---|---|
| 1 | "Ruby,Rails,SQL" |
「Ruby のタグがついた記事」を探すのが困難
| post_id | tag_id |
|---|---|
| 1 | 1 (Ruby) |
| 1 | 2 (Rails) |
タグごとの検索も集計もできる
| id | phone1 | phone2 | phone3 |
|---|---|---|---|
| 1 | 090-... | 080-... | NULL |
4つ目が必要になったら
テーブル構造を変える必要がある
| id | user_id | number |
|---|---|---|
| 1 | 1 | 090-... |
| 2 | 1 | 080-... |
何個でも追加できる
| id | customer_name | item |
|---|---|---|
| 1 | 田中太郎 | りんご |
| 2 | 田中太郎 | みかん |
全行を更新する必要がある
| id | customer_id | item |
|---|---|---|
| 1 | 1 | りんご |
| 2 | 1 | みかん |
名前は customers テーブルの
1箇所だけ直せばいい
| id | product_id | product_name | price |
|---|---|---|---|
| 1 | 5 | りんご | 120 |
| 2 | 5 | りんご | 120 |
| id | commentable_type | commentable_id | body |
|---|---|---|---|
| 1 | Post | 3 | いい記事 |
| 2 | Product | 7 | 気に入った |
| post_id | changed_by | field | old | new |
|---|---|---|---|---|
| 3 | 1 | title | 旧タイトル | 新タイトル |
| 3 | 1 | status | draft | published |