// Alias the left attribute if the left attribute is not from a subqueried main table
// Alias the left attribute if the left attribute is not from a subqueried main table
// When doing a query like SELECT aliasedKey FROM (SELECT primaryKey FROM primaryTable) only aliasedKey is available to the join, this is not the case when doing a regular select where you can't used the aliased attribute
// When doing a query like SELECT aliasedKey FROM (SELECT primaryKey FROM primaryTable)
// only aliasedKey is available to the join, this is not the case when doing a regular
// select where you can't used the aliased attribute
// Through includes are always hasMany, so we need to add the attributes to the mainAttributes no matter what (Real join will never be executed in subquery)
// Through includes are always hasMany, so we need to add the attributes to the mainAttributes no matter what (Real join will never be executed in subquery)
'SELECT TOP(1)'+SqlGenerator.quoteIdentifier(throughAs)+'.'+SqlGenerator.quoteIdentifier(identSource)+' FROM '+SqlGenerator.quoteTable(throughTable,throughAs),
')',
!include.required&&joinType+SqlGenerator.quoteTable(association.source.tableName,tableSource)+' ON '+sourceJoinOn||'',
'IS NOT NULL'
joinType+SqlGenerator.quoteTable(table,as)+' ON '+targetJoinOn,
].join(' '));
'WHERE '+(!include.required&&targetWhere||sourceJoinOn+' AND '+targetWhere),
// Alias the left attribute if the left attribute is not from a subqueried main table
// Alias the left attribute if the left attribute is not from a subqueried main table
// When doing a query like SELECT aliasedKey FROM (SELECT primaryKey FROM primaryTable)
// When doing a query like SELECT aliasedKey FROM (SELECT primaryKey FROM primaryTable) only aliasedKey is available to the join, this is not the case when doing a regular select where you can't used the aliased attribute
// only aliasedKey is available to the join, this is not the case when doing a regular
// select where you can't used the aliased attribute