'Typeorm createQueryBuilder.innnerJoinSelect() not returning the columns of a table
I'm attempting to select columns of two tables tradie,postcode_distance using innerJoinAndSelect but unfortunately, I'm not fetching those columns.
Here's what I'm trying with typeorm createQueryBuilder()
this.createQueryBuilder('tradie')
.innerJoin(
'tradie.categories',
'category',
'category.category_id = :categoryId',
{
categoryId,
},
)
.innerJoinAndSelect(
'postcode_distance',
'postcodeDistance',
'postcodeDistance.source = ANY(tradie.directoryPostcodes)',
)
.where('tradie.plan IN (:...planIds)', { planIds })
.andWhere('postcodeDistance.destination = :postcode', { postcode })
.andWhere('postcodeDistance.driving_distance <= :radius', { radius })
.andWhere('tradie.enable_spiral_search = TRUE')
.andWhere('tradie.is_active = TRUE')
.select('tradie')
Here's the SQL I'm expecting to be generated.
Select t.*,pd.*
FROM tradie t
INNER JOIN tradie_category tc
ON t.tradie_id=tc.tradie_id
INNER JOIN Category c ON
c.category_id=tc.category_id
AND c.category_id=$1
INNER JOIN postcode_distance pd ON
pd.source=ANY(t.directory_postcodes)
WHERE t.plan_id IN($2,$3)
AND pd.destination=$4 AND
pd.driving_distance<=$5 AND
t.enable_spiral_search=TRUE AND
t.is_active=TRUE
Solution 1:[1]
Seems like select() will reset the selected columns above it. Removing select() fixed it
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | TheLoneWolf91193 |