title: How to save many-to-many relation in typeorm?
body: <p>I am trying to make a relation between <code>Posts</code> and <code>Hashtags</code>, here are my both entities,</p>
  <pre class="lang-js prettyprint-override"><code>@Entity('posts')
  export class Posts {
    @PrimaryGeneratedColumn('uuid')
    id: string;
  
    @Column({ length: 200, nullable: true })
    caption: string;
  
    @ManyToMany(() =&gt; Hashtags, (hashtags) =&gt; hashtags.posts, { eager: true })
    @JoinTable({ name: 'posts_hashtags_relation' })
    hashtags: Hashtags[];
  
    @ManyToOne(() =&gt; User)
    @JoinColumn({ name: 'author_id' })
    author: User;
  }
  
  
  @Entity('hashtags')
  export class Hashtags {
    @PrimaryGeneratedColumn('uuid')
    id: string;
  
    @Column()
    hashtag: string;
  
    @ManyToMany(() =&gt; Posts, (post) =&gt; post.hashtags, {
      eager: false,
      cascade: true,
    })
    posts: Posts[];
  
    @CreateDateColumn({ name: 'created_at' })
    createdAt: Date;
  }
  </code></pre>
  <p>By these, typeorm created a database <code>posts_hashtags_relation</code>, with columns <code>postsId</code> and <code>hashtagsId</code>
  And the service by which I am saving hashtags in the hashtags table is like this</p>
  <pre class="lang-js prettyprint-override"><code>async createPost(creator : User, body: CreatePostDto) {
      if (!body.caption) {
        throw new BadRequestException('Post must contain some text');
      }
  
      // Extract hashtags from the post caption body
      const hashtags = body.caption.match(/\#\w+/g); // hashtags are the array of all hashtags in the post caption
  
      if(hashtags){
        for (const hashtag of hashtags) {
          const hashtagEntity = await this.hashtagRepo.findOne({ hashtag });
          if (!hashtagEntity) {
            await this.hashtagRepo.save({ hashtag });
          }
        }
      }
      
      const post = new Posts();
      post.author = creator;
      post.caption = body.caption;
      post.images = body.images;
  
      const resPost = await this.postsRepo.save(post);
  
      return resPost;
    }
  </code></pre>
  <p>But how to save the relation in <code>posts_hashtags_relation</code> table ?</p>