#Many-to-many relationship

7 messages ยท Page 1 of 1 (latest)

craggy willow
#

I have 2 models (TypeORM) that have a many-to-many relationship with each other: Post and Category.
I have created resources (nest g resource post, nest g resource category).

Is this a good way to create and delete many-to-many relationships? (Post controller):
POST request - /post/:id/category/:categoryId
DELETE request - /post/:id/category/:categoryId

Or is there some other better way? (e.g. creating another resource, creating a new controller and service...?)
Thanks

green jackal
#

It's too simple case. Don't overthink it, if it works then it's good. You can just noticed that you can't update multiple categories with it at once.

vast zealot
#

Just thinking you might break the many-to-many relationship into two one-to-many relationships.

versed peak
#

That and you probably want to use names instead of id's if you're going to be cascading non-existent entities ๐Ÿ˜‰

craggy willow
#

thank you for answers ๐Ÿ™‚ It looks like I will have to use 2x one-to-many relationships