如何在Typeorm中创建多对一关系

时间:2020-10-16 07:47:03

标签: mysql typeorm

我想在attendanceschild实体之间建立多对一关系

我想要的结果是连接child_id的{​​{1}}和attendances的{​​{1}}。

下面是我目前的工作,该工作是从我的id实体创建的。

children
typeorm

但是即使我发送了一些json,mysql> desc attendances; +----------------+--------------+------+-----+----------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------+--------------+------+-----+----------------------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | attendance_cd | int(11) | NO | | NULL | | | come_home_time | time | NO | | NULL | | | late_time | time | NO | | NULL | | | memo | varchar(255) | NO | | NULL | | | created_at | datetime(6) | NO | | CURRENT_TIMESTAMP(6) | | | updated_at | datetime(6) | NO | | CURRENT_TIMESTAMP(6) | | | deleted_at | datetime(6) | YES | | NULL | | | child_id | int(11) | YES | MUL | NULL | | +----------------+--------------+------+-----+----------------------+----------------+ 列也没有填充数据。 似乎mysql> desc children; +--------------+--------------+------+-----+----------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------------+--------------+------+-----+----------------------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | user_id | int(11) | NO | MUL | NULL | | | mogu_plus_id | varchar(255) | NO | | NULL | | | first_name | varchar(255) | NO | | NULL | | | middle_name | varchar(255) | YES | | NULL | | | last_name | varchar(255) | NO | | NULL | | | birthday | date | NO | | NULL | | | gender | varchar(255) | NO | | NULL | | | blood_type | varchar(255) | NO | | NULL | | | class | varchar(255) | YES | | NULL | | | entrance_day | varchar(255) | YES | | NULL | | | is_active | int(11) | NO | | NULL | | | created_at | datetime(6) | NO | | CURRENT_TIMESTAMP(6) | | | updated_at | datetime(6) | NO | | CURRENT_TIMESTAMP(6) | | | deleted_at | datetime(6) | YES | | NULL | | +--------------+--------------+------+-----+----------------------+----------------+ child_id没有连接。

id

以下是每个child_id的定义。

mysql> select * from attendances; +----+---------------+----------------+-----------+------+----------------------------+----------------------------+------------+----------+ | id | attendance_cd | come_home_time | late_time | memo | created_at | updated_at | deleted_at | child_id | +----+---------------+----------------+-----------+------+----------------------------+----------------------------+------------+----------+ | 1 | 1 | 11:59:00 | 23:40:00 | test | 2020-10-16 06:50:33.045889 | 2020-10-16 06:50:33.045889 | NULL | NULL | | 2 | 1 | 11:59:00 | 23:40:00 | test | 2020-10-16 06:51:12.863708 | 2020-10-16 06:51:12.863708 | NULL | NULL | | 3 | 1 | 11:59:00 | 23:40:00 | test | 2020-10-16 06:54:06.878678 | 2020-10-16 06:54:06.878678 | NULL | NULL | | 4 | 1 | 11:59:00 | 23:40:00 | test | 2020-10-16 06:55:11.219690 | 2020-10-16 06:55:11.219690 | NULL | NULL | | 5 | 1 | 11:59:00 | 23:40:00 | test | 2020-10-16 07:01:30.290203 | 2020-10-16 07:01:30.290203 | NULL | NULL | | 6 | 1 | 11:59:00 | 23:40:00 | test | 2020-10-16 07:04:14.535198 | 2020-10-16 07:04:14.535198 | NULL | NULL | | 7 | 1 | 11:59:00 | 23:40:00 | test | 2020-10-16 07:06:47.612541 | 2020-10-16 07:06:47.612541 | NULL | NULL | +----+---------------+----------------+-----------+------+----------------------------+----------------------------+------------+----------+ entity关系是否存在错误之处?

id
child_id

0 个答案:

没有答案