diff --git a/models/BaseEntity.cfc b/models/BaseEntity.cfc index a3f7a943..5e4357ca 100644 --- a/models/BaseEntity.cfc +++ b/models/BaseEntity.cfc @@ -381,6 +381,16 @@ component accessors="true" { string tableName = this.tableName(), boolean useParentLookup = true ) { + if ( reFindNoCase( "\s+AS\s+", arguments.column ) ) { + var source = trim( reReplaceNoCase( arguments.column, "\s+AS\s+.*$", "" ) ); + var alias = trim( reReplaceNoCase( arguments.column, "^.*?\s+AS\s+", "" ) ); + return qualifyColumn( + column = source, + tableName = arguments.tableName, + useParentLookup = arguments.useParentLookup + ) & " AS " & alias; + } + if ( findNoCase( ".", arguments.column ) != 0 || !hasAttribute( arguments.column ) || diff --git a/tests/specs/integration/BaseEntity/AsQuerySpec.cfc b/tests/specs/integration/BaseEntity/AsQuerySpec.cfc index d2dc845a..abc77c93 100644 --- a/tests/specs/integration/BaseEntity/AsQuerySpec.cfc +++ b/tests/specs/integration/BaseEntity/AsQuerySpec.cfc @@ -77,6 +77,18 @@ component extends="tests.resources.ModuleIntegrationSpec" { expect( results[ 2 ][ "latestPostId" ] ).toBe( "" ); } ); + it( "can select an aliased entity attribute when returning query data", function() { + var result = getInstance( "User" ) + .select( [ "firstName AS firstName" ] ) + .where( "id", 1 ) + .asQuery( withAliases = false ) + .first(); + + expect( result ).toBeStruct(); + expect( result ).toHaveKey( "firstName" ); + expect( result.firstName ).toBe( "Eric" ); + } ); + it( "can do eager loading", function() { var results = getInstance( "Post" ) .newQuery()