title: typeorm: relation 'xxxx' does not exist
body: <p>this is the table structure I have, a many to many relationship</p>
  <pre><code>CREATE TABLE IF NOT EXISTS destinations.destination
  (
      destinationid integer NOT NULL,
      geolocation json,
      CONSTRAINT pk_destination PRIMARY KEY (destinationid)
  )
  
  CREATE TABLE IF NOT EXISTS destinations.tag
  (
      tagid integer NOT NULL,
      name character varying(50) COLLATE pg_catalog.&quot;default&quot; NOT NULL,
      code character varying(2) COLLATE pg_catalog.&quot;default&quot; NOT NULL,
      CONSTRAINT pk_tag PRIMARY KEY (tagid)
  )
  
  CREATE TABLE IF NOT EXISTS destinations.destination_tag
  (
      destinationid integer NOT NULL,
      tagid integer NOT NULL,
      CONSTRAINT pk_destination_tag PRIMARY KEY (destinationid, tagid),
      CONSTRAINT fk_dest_tag_dest FOREIGN KEY (destinationid)
          REFERENCES destinations.destination (destinationid) MATCH SIMPLE
          ON UPDATE NO ACTION
          ON DELETE NO ACTION,
      CONSTRAINT fk_dest_tag_tag FOREIGN KEY (tagid)
          REFERENCES destinations.tag (tagid) MATCH SIMPLE
          ON UPDATE NO ACTION
          ON DELETE NO ACTION
  )
  </code></pre>
  <p>that is, a destination and tag has a many to many relationship. I created the following classes in TypeORM with Tag holding destinations and Destinations holding tags</p>
  <pre><code>@Entity({ name: 'tag' })
  export class Tag {
  
    @Column({ name: 'tagid', type: 'integer' })
    @PrimaryColumn({ primaryKeyConstraintName: 'pk_tag' })
    tagid: number
  
    @Column({ type: 'varchar', length: 50 })
    name: string
  
    @Column({ type: 'char', length: 2 })
    code: string
  
     
  
    @ManyToMany(() =&gt; Destination, d =&gt; d.tags)
    @JoinTable({
      inverseJoinColumn: {
        name: 'destinationid'
        ,referencedColumnName: 'destinationid'
        ,foreignKeyConstraintName: 'fk_dest_tag_dest'
      },
      joinColumn: {
        name: 'tagid'
        ,referencedColumnName: 'tagid'
        ,foreignKeyConstraintName: 'fk_dest_tag_tag'
      }
    })
    destinations: Destination[]
  }
  
  
  @Entity({ name: 'destination' })
  export class Destination {
  
    @Column({ name: 'destinationid', type: 'integer' })
    @PrimaryColumn({ primaryKeyConstraintName: 'pk_destination' })
    destinationid: number
  
    @Column({ name: 'geolocation', type: 'integer' })
    geolocation: GeoLocation
  
  
    @ManyToMany(() =&gt; Tag,  t =&gt; t.destinations)
    @JoinTable({
      joinColumn: {
        name: 'destinationid'
        , referencedColumnName: 'destinationid'
        , foreignKeyConstraintName: 'fk_dest_tag_dest'
      },
      inverseJoinColumn: {
        name: 'tagid'
        , referencedColumnName: 'tagid'
        , foreignKeyConstraintName: 'fk_dest_tag_tag'
      }
    })
    tags: Tag[]
  }
  </code></pre>
  <p>When I run the following query. I get the error:</p>
  <pre><code>   const row = await rep.findOne({
        relations: [&quot;contents&quot;, &quot;tags&quot;],
        where: {
          destinationid: id
        }
      })
  </code></pre>
  <p>error: error: relation &quot;destinations.destination_tags_tag&quot; does not exist</p>
  <p>This is the sql generated.</p>
  <blockquote>
  <p>query failed: SELECT DISTINCT
  &quot;distinctAlias&quot;.&quot;Destination_destinationid&quot; AS
  &quot;ids_Destination_destinationid&quot; FROM (SELECT
  &quot;Destination&quot;.&quot;destinationid&quot; AS &quot;Destination_destinationid&quot;,
  &quot;Destination&quot;.&quot;geolocation&quot; AS &quot;Destination_geolocation&quot;,
  &quot;Destination__Destination_tags&quot;.&quot;tagid&quot; AS
  &quot;Destination__Destination_tags_tagid&quot;,
  &quot;Destination__Destination_tags&quot;.&quot;name&quot; AS
  &quot;Destination__Destination_tags_name&quot;,
  &quot;Destination__Destination_tags&quot;.&quot;code&quot; AS
  &quot;Destination__Destination_tags_code&quot; FROM &quot;destinations&quot;.&quot;destination&quot;
  &quot;Destination&quot;  LEFT JOIN &quot;destinations&quot;.&quot;<strong>destination_tags_tag</strong>&quot;
  &quot;Destination_Destination__Destination_tags&quot; ON
  &quot;Destination_Destination__Destination_tags&quot;.&quot;destinationid&quot;=&quot;Destination&quot;.&quot;destinationid&quot;
  LEFT JOIN &quot;destinations&quot;.&quot;tag&quot; &quot;Destination__Destination_tags&quot; ON
  &quot;Destination__Destination_tags&quot;.&quot;tagid&quot;=&quot;Destination_Destination__Destination_tags&quot;.&quot;tagid&quot;
  WHERE (&quot;Destination&quot;.&quot;destinationid&quot; = $1)) &quot;distinctAlias&quot; ORDER BY
  &quot;Destination_destinationid&quot; ASC LIMIT 1 -- PARAMETERS: [&quot;12&quot;]</p>
  </blockquote>
  <p>Where does the destination_tags_tag come from? why it doesnt use destination_tags which is the actual table?</p>