Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typeorm): filter query wrongly generated #478

Merged
merged 1 commit into from
Apr 20, 2020

Conversation

joennlae
Copy link
Contributor

This PR fixes this issue #401 and issue #321. As described there (#401) if one filters by a certain field. The return field alias is wrong for type ORM.

Looking at the log, I saw the following QUERY:

SELECT "Comment"."id" AS "Comment_id", "Comment"."text" AS "Comment_text", "post"."id" AS "post_id", "post"."body" AS "post_body", "post"."commentsId" FROM "comment" "Comment" LEFT JOIN "post" "post" ON "post"."commentsId"="Comment"."id" WHERE (Comment.postId = $1)

And doing tests directly in the database and works with this SQL (I added the quotes on WHERE it)

SELECT "Comment"."id" AS "Comment_id", "Comment"."text" AS "Comment_text", "post"."id" AS "post_id", "post"."body" AS "post_body", "post"."commentsId" FROM "comment" "Comment" LEFT JOIN "post" "post" ON "post"."commentsId"="Comment"."id" WHERE ("Comment"."postId" = $1)

source #401 (comment)

I was able to reproduce this. I then tried to fix it with these two lines:

https://github.com/joennlae/crud/blob/5687f88de66d7e56bbae228f1d0739de6241ae8a/packages/crud-typeorm/src/typeorm-crud.service.ts#L788-L789

This above two line didn't work when I started to do some sorting queries. Sorting still needs the alias without ".

Thank you all for this awesome project. I started using it today and I am already a big fan.

@joennlae joennlae changed the title fix(typeorm): query wrong generated fix(typeorm): filter query wrongly generated Apr 19, 2020
@michaelyali michaelyali self-requested a review April 20, 2020 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants