I've been using TypeORM and made some Entities as follows:
User.ts@PrimaryGeneratedColumn() id: numberPost.ts@PrimaryGeneratedColumn() id: number @Column() userId: number
As I didn't want to make relations between User and Post entities, I just made a column named userId at Post.
Here's the question.
I'd like to join two tables and fetch data. But how can I use innerJoinAndSelect or leftJoinAndSelect?
Here's my code:
// getPost.ts
// Attempt 1
const first = await createQueryBuilder()
.select('user')
.from(User, 'user')
.leftJoinAndSelect(Post, 'post', 'post.userId = user.id')
.getMany() // only fetched User data without Post data
// Attempt 2
const second = await createQueryBuilder('user')
.innerJoinAndSelect('user.id', 'userId')
.innerJoinAndMap('user.id', Post, 'post', 'userId = post.userId')
.getMany() // Bad request error
But None of these worked...
I'd like to join User with Post and grab all data (but not using relation). How could I get these data?