-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Column name aliasing broke in v 0.2.29 #7030
Column name aliasing broke in v 0.2.29 #7030
Comments
#6870 appears to be related to count expressions only so I don't think that is the cause. Could you create a minimal sample program or test to recreate this and/or post a query log along with the input/output entity values? |
Sure, here is a simple repro. https://github.com/ddehghan/typeorm-bug the insert works correctly but the findOne() fails. It is falling back to the db column name "id" instead of the alias "id" which points to "new_id" column typeorm: 0.2.29 output:
typeorm: 0.2.28 output:
|
I'm very unsure how the count expression PR caused this issue but I'll take a look. What points you at that specific PR? It sounds like you're doing a |
Test to reproduce - imnotjames@438f577 |
Code confirmed failing in 0.2.29 but also seems to be failing in earlier versions. I tested 0.2.28 and saw the same failures. |
Also tested with 0.2.26 - same deal. Failures ): So a bigger issue than something in the latest release? |
I am not sure about the exact PR that caused this. I just looked at the change list of .29 and guessed. Also I cant repro this on 0.2.26. I tried my example on .24-2.9 and only it fails on .29. |
Ok - steps I followed to verify with that code with the test I had created:
|
Oh :) I see my issue - I mixed up your PK and the |
typeorm/src/query-builder/QueryBuilder.ts Lines 595 to 596 in 37f0d8f
These lines weren't in the original implementation. We added it to fix some implementation weirdness.
So we probably want to do |
we should always prioritize replacement of any property path first, then property names, then database names, then relation values whenever there's ambiguous values fixes typeorm#7030
@ddehghan If you do have a moment and can verify the change that'd be helpful in getting this fixed in the next release! |
Great. It worked. :-) Thanks a lot @imnotjames |
) we should always prioritize replacement of any property path first, then property names, then database names, then relation values whenever there's ambiguous values fixes #7030
…peorm#7042) we should always prioritize replacement of any property path first, then property names, then database names, then relation values whenever there's ambiguous values fixes typeorm#7030
…peorm#7042) we should always prioritize replacement of any property path first, then property names, then database names, then relation values whenever there's ambiguous values fixes typeorm#7030
…peorm#7042) we should always prioritize replacement of any property path first, then property names, then database names, then relation values whenever there's ambiguous values fixes typeorm#7030
…peorm#7042) we should always prioritize replacement of any property path first, then property names, then database names, then relation values whenever there's ambiguous values fixes typeorm#7030
Hi everyone TypeOrm use Class-model as table name in the final query Code : const banners = await AppDataSource.manager.find(Banner, {
where: {
active: true
}
}) TYPE ORM QUERY RESULT : SELECT 'Banner'.'id' AS 'Banner_id', 'Banner'.'image' AS 'Banner_image', 'Banner'.'description' AS 'Banner_description', 'Banner'.'type' AS 'Banner_type', 'Banner'.'price' AS 'Banner_price', 'Banner'.'link' AS 'Banner_link', 'Banner'.'active' AS 'Banner_active', 'Banner'.'customar_id' AS 'Banner_customar_id', 'Banner'.'updated_at' AS 'Banner_updated_at', 'Banner'.'created_at' AS 'Banner_created_at' FROM 'banners' 'Banner' WHERE ('Banner'.'active' = ?)'
|
~~It looks like bug fix #6870 caused this regression. ~~ Edit from @imnotjames: It seems to be #4760
If you have a table with Primary key and another column with the same name, then the Primary ID name gets precedence. 0.2.28 was working correctly.
Issue Description
We have a table for example called Book which had a DB primary key in the db. But we don't want to expose this to the users so we have created another column Book_id which has a UUID which we use in our API
Expected Behavior
" Book.id " should be mapped to (book_id column in the database)
Actual Behavior
" Book.id " is mapped to (id column in the database)
My Environment
Not os or env dependent issue
| TypeORM version : 0.2.29
Relevant Database Driver(s)
aurora-data-api
aurora-data-api-pg
better-sqlite3
cockroachdb
cordova
expo
mongodb
mysql
nativescript
oracle
postgres
react-native
sap
sqlite
sqlite-abstract
sqljs
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
I can help test the resolution
The text was updated successfully, but these errors were encountered: