[ad_1]
Maybe someone already got a decision for sorting data in DB by numbers and letters. If I get query from the code below it’s works good in MySQL, but typeorm show an error: “”SUBSTR(org” alias was not found. Maybe you forgot to join it? on GET … called by undefined”.
createQueryBuilder('org')
.select([
'org.id',
'org.name',
'org.end_dt',
'ar.id',
'ar.role_id',
'person.kw_uid',
'person.first_name',
'person.last_name',
])
.leftJoin(
'org.association_roles',
'ar',
ar.end_dt is NULL,
)
.leftJoin('ar.person', 'person')
.where('parent_org_id = :mcID', { mcID })
.andWhere(org_type_id in (${ORG_TYPE_ID.team}, ${ORG_TYPE_ID.wwTeam}))
.take(limit)
.skip(offset)
.orderBy('SUBSTR(org.name FROM 1 FOR 1), LPAD(lower(org.name), 10, 0)');
I can not replace .take with .limit, and .skip with .offset because it will not work correctly.
org.name can be like
- Example
- Example 12
- Example 1
- Example0
[ad_2]