Here are my entities
I am trying to run this query to get all the channels along with latestMessage sent in each channel to be mapped to latestMessage property of the channel entity
const channels = this.channelRepository
.createQueryBuilder('c')
.innerJoinAndMapOne(
'c.latestMessage',
(sub) => {
return sub
.from(Message, 'm')
.orderBy({ 'm.createdAt': 'DESC' })
.limit(1);
},
'latestMessage',
'latestMessage.channel = c.id',
);
return channels.getMany();
However I get the following error : QueryFailedError: missing FROM-clause entry for table “latestmessage”
I have assigned an alias for the subquery as latestMessage then why does it show that i cant select from it.
Any help would be appreciated.