postgresql - how to use subquery value on left join column in typeorm? - Stack Overflow

admin2025-04-27  3

  const qb = dbConnection
    .getRepository(AssignedWorkload)
    .createQueryBuilder("aw")
    .leftJoinAndSelect("aw.workload", "workload")
    .leftJoinAndMapMany(
      "aw.assignments",
      "aw.assignedInteractions",
      "workloadInteraction"
    )
    .leftJoinAndSelect("workloadInteraction.interaction", "interaction")
    .leftJoinAndSelect("workloadInteraction.evaluation", "evaluation")
    .leftJoinAndSelect("workload.interactionFilter", "interactionFilter")
    .leftJoinAndMapOne(
      "interaction.metadata",
      `interaction.${IntegrationSystem.CHAT.toLowerCase()}Metadata`,
      "metadata",
      `metadata.id = interaction.${IntegrationSystem.CHAT.toLowerCase()}MetadataId`
    );

I have this query that I created. Instead of hardcoding the left join column as such interaction.${IntegrationSystem.CHAT.toLowerCase()}Metadata. My "workload" table has a relationship with interaction_filter table where can the IntegrationSystem value from the interaction_filter.integrationSystem column.

Would it be possible to run a subquery to join workload.interactionFilter then select the interactionFilter.integrationSystem column value then use that value while left joining interaction.metadata or I should execute a different query to get the system value?

转载请注明原文地址:http://anycun.com/QandA/1745706504a91093.html