question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ManyToMany Controller

See original GitHub issue

Hi, first of all thank you for the amazing library.

My situation is the following:

  • User entity
export class User {
  // ...
  @ManyToMany(type => Document, document => document.users)
  @JoinTable()
  documents: Document[];
}
  • Document entity
export class Document {
  // ...
  @ManyToMany(type => User, user => user.documents)
  users: User[];
}

The code above generates a third table (obviously) with userId and documentId. Is there a way to create a controller that exposes “nested endpoints” and that automatically handles this type of relationship (with filters, etc.)?

For example:

  • GET /users/:id/documents - retrieves specific user documents
  • POST /users/:id/documents - creates the new document and also populates the intermediate table

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:19
  • Comments:7

github_iconTop GitHub Comments

1reaction
jbjhjmcommented, Oct 7, 2019

Partially related to https://github.com/nestjsx/crud/issues/239 …which could be taken into account. Features to handle ManyToMany relations and their “middleman” table (ordering, custom fields) would be a powerful addition.

0reactions
josmocommented, Dec 11, 2020

@acepace do you have an example somewhere on how you have it working with the “owning” side?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Many to many relationships in the controller - Stack Overflow
Product and WishList make a Many to Many relationship (at least to me). In a m---m relationship, the belongsToMany() method needs to be ......
Read more >
JPA Many to Many example with Hibernate in Spring Boot
Finally, we create controller that provides APIs for CRUD operations: creating, retrieving, updating, deleting and finding Tutorials and Tags.
Read more >
Resource Controller for many to many pivot table to enter data ...
I want to do data entry CRUD in joined many to many table via a separate forms from a resource controller actions and...
Read more >
Eloquent ORM Many-to-Many Relationships-Laravel | Medium
I have two articles that explain the one-to-one and one-to-many relationships in Laravel, so in this article I'll explain about many-to-many relationships.
Read more >
Making Many-to-Many Associations in Controllers
Ruby and Rails · Rails with Active Record; Making Many-to-Many Associations in Controllers. Text. In the last lesson, we covered setting up ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found