Skip to content

Commit

Permalink
orderBy should not blow away select clause joins
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdickinson committed Mar 3, 2016
1 parent 7a8defc commit 1c09b39
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lib/queryset.js
Expand Up @@ -589,6 +589,15 @@ function buildSelect (dao, db, where, bounds, order, values, onlyFields, rawFiel
`)
}

for (var join of getJoins(dao, where, seenJoin)) {
addJoin(join)
if (!seenSelect.has(join.to)) {
selectClause.push(
join.to.contributeColumns(pfx.get(join.to), filterOnlyFields)
)
}
seenSelect.add(join.to)
}
order = (order || []).map(col => {
var order = 'ASC'
if (col[0] === '-') {
Expand All @@ -601,15 +610,6 @@ function buildSelect (dao, db, where, bounds, order, values, onlyFields, rawFiel
}
return `"${info.dao.tableName}"."${info.col.column}" ${order}`
})
for (var join of getJoins(dao, where, seenJoin)) {
addJoin(join)
if (!seenSelect.has(join.to)) {
selectClause.push(
join.to.contributeColumns(pfx.get(join.to), filterOnlyFields)
)
}
seenSelect.add(join.to)
}

var offset = bounds[0]
var limit = bounds[1] - bounds[0]
Expand Down Expand Up @@ -691,13 +691,13 @@ function buildInsert (dao, db, data, values) {
}

const rows = []
for (var i = 0; i < preppedData.length; ++i) {
for (var x = 0; x < preppedData.length; ++x) {
const row = []
for (var col of insertSchema) {
if (col in preppedData[i]) {
if (col in preppedData[x]) {
row.push(
col in preppedData[i]
? '$' + values.push(preppedData[i][col])
col in preppedData[x]
? '$' + values.push(preppedData[x][col])
: 'DEFAULT'
)
}
Expand Down

0 comments on commit 1c09b39

Please sign in to comment.