我有以下架构:
mysql> describe event_state;
+---------------------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+---------------------+------+-----+---------+----------------+
| id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| event_id | bigint(20) unsigned | NO | MUL | NULL | |
| state_id | bigint(20) unsigned | NO | MUL | NULL | |
| gender | varchar(191) | NO | | NULL | |
| value | decimal(8,2) | NO | | NULL | |
| value_type | varchar(191) | NO | | NULL | |
| display_measurement | varchar(191) | NO | | NULL | |
| deleted_at | timestamp | YES | | NULL | |
| created_at | timestamp | YES | | NULL | |
| updated_at | timestamp | YES | | NULL | |
+---------------------+---------------------+------+-----+---------+----------------+
10 rows in set (0.01 sec)
mysql> describe events;
+-------------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------------------+------+-----+---------+----------------+
| id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(191) | NO | UNI | NULL | |
| category_id | bigint(20) unsigned | NO | MUL | NULL | |
| created_at | timestamp | YES | | NULL | |
| updated_at | timestamp | YES | | NULL | |
| deleted_at | timestamp | YES | | NULL | |
+-------------+---------------------+------+-----+---------+----------------+
6 rows in set (0.01 sec)
mysql> describe states;
+------------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------------------+------+-----+---------+----------------+
| id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(191) | NO | UNI | NULL | |
| created_at | timestamp | YES | | NULL | |
| updated_at | timestamp | YES | | NULL | |
| deleted_at | timestamp | YES | | NULL | |
+------------+---------------------+------+-----+---------+----------------+
5 rows in set (0.01 sec)
在event_state
表中,我可以具有相同的event_id和state_id,并附加了不同的性别(男性或女性)。 Larvel Nova不允许通过资源中的BelongsToMany
进行此操作。