Repository navigation
Conversation
minifyAlias option in findOne, findAll, and findAndCountAllminifyAlias option in findOne, findAll, and findAndCountAll
|
Hey @ephys I kinda need enlightenment here! Like I believe this should atleast push it in the |
|
That lets the user know the option is available but it's not actually doing anything because the code never checks if the option bag the method received has the option enabled. QueryGenerator only checks for the global version of the option right now |
|
Can you add some tests on how it should behave? |
|
Hey give me some time on this! Will start working on it asap! |
…opt-for-findone-findall-findandcountall
…opt-for-findone-findall-findandcountall
…opt-for-findone-findall-findandcountall
|
@frostzt not 100% sure what you mean, but you should be able to enable logging to see the generated SQL queries, you can pass the option to e.g. |
|
Hey @WikiRik actually yeah that logging is working as I expected and the results are also what I expected its just that I wanted to get the generated SQL which I can then compare to some expected SQL. |
|
@frostzt in unit/integration tests you mean? Or just for you during development? |
…opt-for-findone-findall-findandcountall
|
I just realized that seems like that thing is not working with any other dialects except Postgres! And that's why the tests for alias minification are only for Postgres! |
|
The only integration tests we currently have for sequelize/packages/core/test/unit/query-generator/select-query.test.ts Lines 510 to 531 in c2fed08 So maybe as a first step we need to implement the integration tests for the other dialects as well? Then we know it works globally for all dialects and then we can start looking into adding the option on specific queries |
|
@WikiRik makes sense I'll actually start by writing for each dialect that I know about 😅 |
|
@WikiRik after debugging around a bit I found out few things. So there are few stuff that are actually not available in any dialect except Postgres, first only in Postgres we are mapping the join aliases! Another thing is; why the other dialects are throwing errors (failing the integration test) is that we are not remapping the columns that were aliased. For example, doing The change now should make that integration test pass for MySQL too. @ephys what are your thoughts on this? Am I even right here? |
|
The last failing test is a fun one. EDIT: The test name is a bit long so I ran the wrong test individually. It fails either way |
😅 yeah I think its a little tricky but when I put the logs I saw something have a look! If you generate a query in the main branch without any of my changes I get this SELECT
"Task".*,
"category"."id" AS "_1",
"category"."createdAt" AS "_2",
"category"."updatedAt" AS "_3"
FROM (
SELECT
*
FROM (
SELECT
"id",
"title",
"category_id" AS "_0",
"createdAt",
"updatedAt",
"UserId"
FROM
"Tasks" AS "Task"
WHERE
"Task"."UserId" = 1
ORDER BY
"Task"."title" ASC
LIMIT 2) AS sub
UNION ALL
SELECT
*
FROM (
SELECT
"id",
"title",
"category_id" AS "_0",
"createdAt",
"updatedAt",
"UserId"
FROM
"Tasks" AS "Task"
WHERE
"Task"."UserId" = 2
ORDER BY
"Task"."title" ASC
LIMIT 2) AS sub) AS "Task"
LEFT OUTER JOIN "Categories" AS "category" ON _0 = "category"."id";And here is what happens when you switch to my code: SELECT
"Task".*,
"category"."id" AS "_1",
"category"."createdAt" AS "_2",
"category"."updatedAt" AS "_3"
FROM (
SELECT
*
FROM (
SELECT
"id",
"title",
"category_id" AS "categoryId",
"createdAt",
"updatedAt",
"UserId"
FROM
"Tasks" AS "Task"
WHERE
"Task"."UserId" = 1
ORDER BY
"Task"."title" ASC
LIMIT 2) AS sub
UNION ALL
SELECT
*
FROM (
SELECT
"id",
"title",
"category_id" AS "categoryId",
"createdAt",
"updatedAt",
"UserId"
FROM
"Tasks" AS "Task"
WHERE
"Task"."UserId" = 2
ORDER BY
"Task"."title" ASC
LIMIT 2) AS sub) AS "Task"
LEFT OUTER JOIN "Categories" AS "category" ON _0 = "category"."id";Do you see that |
|
We're not passing the option to the subquery |
|
Thanks a lot @WikiRik 😅 gotta read the code more I never knew that thing existed there! There are few integration tests that fail though they are something with pooling! |
…opt-for-findone-findall-findandcountall
|
@frostzt I think you just got unlucky with failing tests. I also didn't know that it existed there, but I was logging the options passed to |
WikiRik
left a comment
There was a problem hiding this comment.
Three small comments, but I think what's I'm still missing here is integration tests for on a local level instead of the global level. So if you add those I think we should be good to merge
|
@ephys I think this is ready to go! |
|
@ephys bump just in case! |
ephys
left a comment
There was a problem hiding this comment.
Looks really good! My last two comments are super minor
Thank you so much for working on this
|
I'm still missing integration tests for setting the option locally but we can add those in a future PR as well |
|
No you're right, this PR should add at least one integration test in |
…opt-for-findone-findall-findandcountall
|
Thanks for working on this! I think we're good to go |
|
Fully up to you :) |
Pull Request Checklist
Description Of Change
Closes #15361
Support
minifyAliasoption in static methods forfindOne,findAll, andfindAndCountAll.