Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ManyToMany with private field #699

Closed
mbayou opened this issue Jul 24, 2017 · 2 comments
Closed

ManyToMany with private field #699

mbayou opened this issue Jul 24, 2017 · 2 comments

Comments

@mbayou
Copy link

mbayou commented Jul 24, 2017

Hi,

I try to create entity with relation many to many, but I want it on private field, so I created a getter.

/**     
 * User's circles     
 */     
@ManyToMany((type) => ActivityCircle, (activityCircle) => activityCircle.getUsers, {lazy: true})     
 private circles: ActivityCircle[];     
/**
   * Circle's users
   */
  @ManyToMany((type) => User, (user) => user.getCircles, {lazy: true})
  @JoinTable()
  private users: User[];

When I tried it an error occurred

{"message":"JoinTable is missing on User#circles many-to-many relationship. You need to put JoinTable decorator on it.","stack":"MissingJoinTableError: JoinTable is missing on User#circles many-to-many relationship. You need to put JoinTable decorator on it....

Do you have any solution to fix it ?

Thanks you.

@pleerock
Copy link
Member

no, you can't use getter. Just do:

  @ManyToMany((type) => User, "circles", {lazy: true})
  @JoinTable()
  private users: User[];

But first think if you really need getters (mistake #1 of users who come from java-like languages thinking they must use getters here as well).

Also instead of doing {lazy: true} here you should do private users: Promise<User[]> and note lazy relations is a very specific feature.

@mbayou
Copy link
Author

mbayou commented Jul 24, 2017

Thank you, it works ! I know the element of getter and setter but I have some constraints, however, really thank you for your quick response. :)

@mbayou mbayou closed this as completed Jul 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants