mysql
1 2MySQL [cakephp_system]> select * from customers; 3+----+------+-----------+---------------+-----------+--------+---------------------+---------------------+---------------------+---------+ 4| id | name | line_type | contract_type | agency_id | status | contract_day | created | modified | deleted | 5+----+------+-----------+---------------+-----------+--------+---------------------+---------------------+---------------------+---------+ 6| 3 | 佐藤 | 0 | 0 | NULL | 0 | 2019-08-02 07:21:00 | 2019-08-02 07:21:06 | 2019-08-02 07:21:06 | 1 | 7| 4 | 伊藤 | 0 | 0 | NULL | 0 | 2019-08-02 07:21:00 | 2019-08-02 07:21:16 | 2019-08-02 07:21:16 | 1 | 8| 5 | 田中 | 0 | 0 | NULL | 0 | 2019-08-02 07:21:00 | 2019-08-02 07:21:26 | 2019-08-02 07:21:26 | 1 | 9+----+------+-----------+---------------+-----------+--------+---------------------+---------------------+---------------------+---------+
mysql
1MySQL [cakephp_system]> desc customers; 2+---------------+-------------+------+-----+---------+----------------+ 3| Field | Type | Null | Key | Default | Extra | 4+---------------+-------------+------+-----+---------+----------------+ 5| id | int(11) | NO | PRI | NULL | auto_increment | 6| name | varchar(50) | YES | | NULL | | 7| agency_id | int(11) | YES | | NULL | | 8| created | datetime | YES | | NULL | | 9| modified | datetime | YES | | NULL | | 10| deleted | int(11) | YES | | 0 | | 11+---------------+-------------+------+-----+---------+----------------+
mysql
1MySQL [cakephp_system]> desc agencies; 2+-------------+-------------+------+-----+---------+----------------+ 3| Field | Type | Null | Key | Default | Extra | 4+-------------+-------------+------+-----+---------+----------------+ 5| id | int(11) | NO | PRI | NULL | auto_increment | 6| agency_name | varchar(50) | YES | | NULL | | 7| created | datetime | YES | | NULL | | 8| modified | datetime | YES | | NULL | | 9| deleted | int(11) | YES | | 0 | | 10+-------------+-------------+------+-----+---------+----------------+
【やりたい事】
customersテーブルでagenciesテーブルのagency_nameカラムを使用したい。
とある課題をしており、テーブル作成に関しては指定があり上記の通り作成しました。
自分の予想はcustomersテーブルのagency_idカラムにagenciesテーブルのagency_name
カラムを当てはめると思っているのですが、どうしたら当てはめることができますか?
ちなみに各テーブルの操作はcakephpで行います。
使い方としてはcakephpのviewページでagenciesテーブルに新規の会社名を登録するとします。
MySQL [cakephp_system]> select * from agencies;
+----+--------------+---------------------+---------------------+---------+
| id | agency_name | created | modified | deleted |
+----+--------------+---------------------+---------------------+---------+
| 1 | ○○有限会社 | 2019-08-02 04:42:54 | 2019-08-02 04:42:54 | 1 |
| 2 | ○○株式会社 | 2019-08-02 04:43:07 | 2019-08-02 04:43:07 | 1 |
| 3 | ○○合同会社 | 2019-08-02 04:43:41 | 2019-08-02 04:43:41 | 1 |
| 4 | ○○合名会社 | 2019-08-02 04:43:52 | 2019-08-02 04:43:52 | 1 |
+----+--------------+---------------------+---------------------+---------+
続いてcakephpの別のviewページで誰がどこの会社に勤めているかを登録します。
そのデータをcustomersテーブルに保存します。
登録するときのviewページでagency_idカラム(会社名)のinputをプルダウン形式で選択できるようにしたいです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/02 05:44
2019/08/02 05:45
2019/08/02 05:46
2019/08/02 06:53
2019/08/02 06:54
2019/08/02 06:54
2019/08/02 06:56
2019/08/02 07:08
2019/08/02 07:12
2019/08/02 07:21
2019/08/02 07:22
2019/08/02 07:22
2019/08/02 07:24
2019/08/02 07:30
2019/08/02 07:35
2019/08/02 07:35
2019/08/02 07:41
2019/08/02 07:46