Lucid: [V5] ManyToMany pivot tables do have NULL created_at / updated_at

Created on 8 Oct 2020  路  3Comments  路  Source: adonisjs/lucid

It's interesting that when a new entity is added to a many to many relationship, the pivot table should at least have a created_at. This is very useful to know when the relation was created. Eg. to know when a user joined a team.

Package version

8.4.4

Node.js and npm version

  • Node: 14.4.0
  • NPM: 6.14.7

Sample Code (to reproduce the issue)

  • Code
const team = await auth.user!.related('teams').create({
  name: 'My amazing team',
})
  • Produced output
mysql> select id, name from users;
+----+-----------------+
| id | name            |
+----+-----------------+
|  1 | 脠rik C. For茅s   |
+----+-----------------+
1 row in set (0.00 sec)

mysql> select id, name from teams;
+----+-----------------+
| id | name            |
+----+-----------------+
|  2 | My amazing team |
+----+-----------------+
1 row in set (0.00 sec)

mysql> select * from team_user;
+----+---------+---------+------------+------------+
| id | team_id | user_id | created_at | updated_at |
+----+---------+---------+------------+------------+
|  1 |       2 |       1 | NULL       | NULL       |
+----+---------+---------+------------+------------+
1 row in set (0.00 sec)
Medium Minor On Hold Enhancement

Most helpful comment

Hello! Sorry for the late reply. This requires some thinking at the API level to see the best way to expose timestamps management of the pivot table without asking one to create a separate model. I don't have a good answer right now, but I will get back to it.

All 3 comments

I can try making a PR if that was relatively easy to do.

Hello! Sorry for the late reply. This requires some thinking at the API level to see the best way to expose timestamps management of the pivot table without asking one to create a separate model. I don't have a good answer right now, but I will get back to it.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings