nestjs-paginate icon indicating copy to clipboard operation
nestjs-paginate copied to clipboard

Cannot find alias for relation at xxx

Open denniscachau00 opened this issue 2 years ago • 3 comments

Hi,

I'm having a problem when I want to add conditions using relations fields.

Here is where I call the paginate function: paginate(query, this.taskMessagesRepository, { relations: ['message'], where: { message: { deleted: false, }, }, sortableColumns: ['id', 'message.deleted'], });

Here are my entites: export class Message { ... @Index() @Column({ type: 'boolean', default: false }) deleted: boolean; }

export class TaskMessage { ... @ManyToOne(() => Message, { nullable: false }) message: Message; }

The error is "Cannot find alias for relation at message".

Please note that, when I want to display a particular task message with a message.id where statement, the condition pick the messageId of the TaskMessage table.

I don't know if it comes from the library or not but when I copy the conditions and relations using "TypeOrm.find", it works.

(I used the 2.6.0 version of the library). Thanks !

denniscachau00 avatar May 30 '22 13:05 denniscachau00

I am not quite sure. Could be due to the nested where. I think we don't have a test covering those.

You could either address this with a PR or use an hardcode an EQ filter on your query.

ppetzold avatar Jun 03 '22 19:06 ppetzold

Hi @ppetzold ,

Thanks for your reply. Indeed, I added the filter in the query waiting for a "cleaner" fix. I plan to see where the problem is in the library but haven't had the time yet :) Will see in the next few days

Dennis

denniscachau00 avatar Jun 03 '22 19:06 denniscachau00

Cool. If you wanna have look. Probably this needs some alias transformation:

https://github.com/ppetzold/nestjs-paginate/blob/master/src/paginate.ts#L228

ppetzold avatar Jun 03 '22 19:06 ppetzold

okay, till now its not fixed

LuckyArdhika avatar Mar 12 '23 10:03 LuckyArdhika

this is/was not an issue of this package. it's typeorm related.

https://github.com/typeorm/typeorm/pull/7805

fixed this for one-to-one and many-to-one. one-to-many still unsupported.

https://github.com/ppetzold/nestjs-paginate/commit/e8705e205b65cfed936db4f4b015c4338065aff9

closing

ppetzold avatar Mar 22 '23 19:03 ppetzold