Having unnecessary leftJoin in TypeORM query

Viewed 551

I have two entities,

@Entity('forms')
export class Form {
  // Form values
  // We set eager to true so that the values are loaded when we do an upsert
  @OneToMany('FormValueText', 'form', { eager: true, cascade: true })
  textValues: FormValueText[];
 
  @Column({ type: 'smallint' })
  @Field()
  version: number;

  @Column({ type: 'text' })
  @Field()
  projectID: string;
}


@Entity('formValuesText')
export class FormValueText {
  @ManyToOne('Form', 'textValues')
  @JoinColumn({ name: 'formID' })
  form: Form

  @Column({ type: 'varchar' })
  @Field()
  value: string;
}

When I try to query from first entity(form)'s service

repo.find({
      select: ['version'],
      where: { projectID },
    });

the query includes LEFT JOIN with formValuesText

SELECT
    "Form"."version" AS "Form_version", "Form"."id" AS "Form_id"
FROM
    "forms" "Form"
    LEFT JOIN "formValuesText" "Form_textValues" ON "Form_textValues"."formID" = "Form"."id"
WHERE ("Form"."projectID" = $1)
AND("Form"."deletedAt" IS NULL)

Expectation

SELECT
    "Form"."version" AS "Form_version", "Form"."id" AS "Form_id"
FROM
    "forms" "Form"
WHERE ("Form"."projectID" = $1)
AND("Form"."deletedAt" IS NULL)

is there a way to not have LEFT JOIN in the query?

1 Answers
Related