You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue: @rewiko/crud-typeorm generates this query (and other similar ones in different tables) which has operated fine in local and staging environments using SQLite and an older version of MySql, but failed in an environment using MySql 8
SELECT`TargetEvent`.`id`AS`TargetEvent_id`,
`TargetEvent`.`slug`AS`TargetEvent_slug`,
`TargetEvent`.`displayName`AS`TargetEvent_displayName`FROM`target_event``TargetEvent`WHERE (LOWER(targetEvent.slug) LIKE ?) <---- this is the problem part of the query in productionORDER BY`TargetEvent_displayName`ASCLIMIT25-- PARAMETERS: ["%stay%"]
Diagnosis:
in production it seems to require that the WHERE clause be title case (LOWER(TargetEvent.slug) LIKE ?) rather than the generated camel case targetEvent . I have tested and confirmed this directly in the mysql cli interface where the title case version works, and the camelCase version returns an error "Unknown column 'targetEvent.slug' in 'where clause'"
The change in the diff below results in the following query that satisfied my MySql 8 environment:
SELECT`TargetEvent`.`id`AS`TargetEvent_id`,
`TargetEvent`.`slug`AS`TargetEvent_slug`,
`TargetEvent`.`displayName`AS`TargetEvent_displayName`FROM`target_event``TargetEvent`WHERE (LOWER(`TargetEvent`.`slug`) LIKE ?)
ORDER BY`TargetEvent_displayName`ASCLIMIT25-- PARAMETERS: ["%stay%"]
Here is the diff that solved my problem:
diff --git a/node_modules/@rewiko/crud-typeorm/lib/typeorm-crud.service.js b/node_modules/@rewiko/crud-typeorm/lib/typeorm-crud.service.js
index 1475728..3e4643d 100644
--- a/node_modules/@rewiko/crud-typeorm/lib/typeorm-crud.service.js+++ b/node_modules/@rewiko/crud-typeorm/lib/typeorm-crud.service.js@@ -570,7 +570,10 @@ class TypeOrmCrudService extends crud_1.CrudService {
const dbColName = this.entityColumnsHash[field] !== field ? this.entityColumnsHash[field] : field;
return `${i}${this.alias}${i}.${i}${dbColName}${i}`;
case 2:
- return field;+ // original code+ // return field;+ // Custom code: Ensure alias is included+ return `${this.alias}.${cols[1]}`;
default:
return cols.slice(cols.length - 2, cols.length).join('.');
}
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch
@rewiko/[email protected]
for the project I'm working on.Issue:
@rewiko/crud-typeorm
generates this query (and other similar ones in different tables) which has operated fine in local and staging environments using SQLite and an older version of MySql, but failed in an environment using MySql 8Diagnosis:
in production it seems to require that the WHERE clause be title case (
LOWER(TargetEvent.slug) LIKE ?)
rather than the generated camel case targetEvent . I have tested and confirmed this directly in the mysql cli interface where the title case version works, and the camelCase version returns an error "Unknown column 'targetEvent.slug' in 'where clause'"The change in the diff below results in the following query that satisfied my MySql 8 environment:
Here is the diff that solved my problem:
This issue body was partially generated by patch-package.
The text was updated successfully, but these errors were encountered: