'QueryFailedError: the column message.textIdmessage does not exist
I'm having a little problem with typeorm and postgre.
Here are the two entities I use :
@Entity('message')
export class Msg {
@PrimaryColumn()
idmessage: number;
@Column()
iduser: number;
@Column()
idconversation: number;
@Column()
date: Date;
@OneToOne(() => Txt)
@JoinColumn()
text: Txt;
}
@Entity('text')
export class Txt {
@PrimaryColumn()
idmessage: number;
@Column()
message: string;
@OneToOne(() => Msg)
msg: Msg;
}
So I have and idmessage field in both entities to link them.
And here is the function I call to retrieve all the messages from the user with his userId.
const query = await this.MsgsRepository.createQueryBuilder("message")
.innerJoinAndSelect("message.text", "text")
.where("message.iduser = :_userId", {_userId})
.getRawMany();
return query;
But when I call this function, I get this error :
QueryFailedError: la colonne message.textIdmessage n'existe pas
at QueryFailedError.TypeORMError [as constructor] (C:\Users\Julien Brd\Documents\GitHub\chatapp-back\src\error\TypeORMError.ts:7:9)
at new QueryFailedError (C:\Users\Julien Brd\Documents\GitHub\chatapp-back\src\error\QueryFailedError.ts:9:9)
at PostgresQueryRunner.<anonymous> (C:\Users\Julien Brd\Documents\GitHub\chatapp-back\src\driver\postgres\PostgresQueryRunner.ts:263:19)
at step (C:\Users\Julien Brd\Documents\GitHub\chatapp-back\node_modules\tslib\tslib.js:143:27)
at Object.throw (C:\Users\Julien Brd\Documents\GitHub\chatapp-back\node_modules\tslib\tslib.js:124:57)
at rejected (C:\Users\Julien Brd\Documents\GitHub\chatapp-back\node_modules\tslib\tslib.js:115:69)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
This is the query, I don't know why it tries to get the "textIdmessage" field :
SELECT "message"."idmessage" AS "message_idmessage", "message"."iduser" AS "message_iduser", "message"."idconversation" AS "message_idconversation", "message"."date" AS "message_date", "message"."textIdmessage" AS "message_textIdmessage", "text"."idmessage" AS "text_idmessage", "text"."message" AS "text_message" FROM "message" "message" INNER JOIN "text" "text" ON "text"."idmessage"="message"."textIdmessage" WHERE "message"."iduser" = :_userId
Thanks a lot for helping me :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
