ORM: attribute in square brackets is NOT resolved inside attribute mappings, if the mapping is used in join
I have the following attribute:
{
"name": "organizationID",
"caption": "Organization",
"dataType": "Entity",
"associatedEntity": "org_organization",
"mapping": [
{
"name": "MSSQL2012",
"expressionType": "Expression",
"expression": "(SELECT TOP 1 ts.parentID FROM org_organization org JOIN org_unit_ts ts ON ts.parentID=org.ID WHERE ts.objectID=[costCenterID] ORDER BY LEVEL)"
},
{
"name": "PostgreSQL",
"expressionType": "Expression",
"expression": "(SELECT ts.parentID FROM org_organization org JOIN org_unit_ts ts ON ts.parentID=org.ID WHERE ts.objectID=[costCenterID] ORDER BY LEVEL LIMIT 1)"
}
]
},
If I use it like that:
UB.Repository('pln_UncoveredDemand').attrs('organizationID').limit(10).select().then(console.table)
Everything is OK, because the expression is used inside SELECT clause, as attribute expression.
But once I start using it like:
UB.Repository('pln_UncoveredDemand').attrs('organizationID.name').limit(10).select().then(console.table)
It does not work, because it uses the expression for join, and it looks like in such a case attributes in squire brackets are NOT resolved, here is the piece of SQL generated - note the [costCenterID]
, which shall really be A01.costCenterID
:
LEFT JOIN org_organization A02 ON A02.ID=(SELECT ts.parentID FROM org_organization org
JOIN org_unit_ts ts ON ts.parentID=org.ID
WHERE ts.objectID=[costCenterID] ORDER BY LEVEL LIMIT 1)