Skip to content

Commit

Permalink
fix: select + addOrderBy broke in 0.3.14 (#9961)
Browse files Browse the repository at this point in the history
* added test for #9960
* fixing the issue
* limiting only to postgres because of NULLS FIRST syntax
* lint
  • Loading branch information
pleerock committed Apr 18, 2023
1 parent 3d67901 commit 0e56f0f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/query-builder/SelectQueryBuilder.ts
Expand Up @@ -2515,9 +2515,7 @@ export class SelectQueryBuilder<Entity extends ObjectLiteral>
column.databaseName,
)
return (
this.escape(orderAlias) +
" " +
orderBys[columnName]
this.escape(orderAlias) + " " + orderValue
)
}
}
Expand Down
12 changes: 12 additions & 0 deletions test/github-issues/9960/entity/ExampleEntity.ts
@@ -0,0 +1,12 @@
import { Entity } from "../../../../src/decorator/entity/Entity"
import { Column } from "../../../../src/decorator/columns/Column"
import { PrimaryGeneratedColumn } from "../../../../src/decorator/columns/PrimaryGeneratedColumn"

@Entity()
export class ExampleEntity {
@PrimaryGeneratedColumn()
id: number

@Column()
name: string
}
42 changes: 42 additions & 0 deletions test/github-issues/9960/issue-9960.ts
@@ -0,0 +1,42 @@
import { DataSource } from "../../../src"
import {
closeTestingConnections,
createTestingConnections,
reloadTestingDatabases,
} from "../../utils/test-utils"
import { ExampleEntity } from "./entity/ExampleEntity"
import { expect } from "chai"

describe("github issues > #9960", () => {
let dataSources: DataSource[]

before(async () => {
dataSources = await createTestingConnections({
entities: [ExampleEntity],
enabledDrivers: ["postgres"],
})
})

beforeEach(() => reloadTestingDatabases(dataSources))
after(() => closeTestingConnections(dataSources))

it("select + order by must work without issues", async () => {
await Promise.all(
dataSources.map(async (dataSource) => {
const example1 = new ExampleEntity()
example1.name = "example #1"
await dataSource.manager.save(example1)

const examples = await dataSource.manager
.createQueryBuilder(ExampleEntity, "example")
.select(["example.id", "example.name"])
.addOrderBy("example.name", "DESC", "NULLS LAST")
.take(1)
.skip(0)
.getMany()

expect(examples).to.be.eql([{ id: 1, name: "example #1" }])
}),
)
})
})

0 comments on commit 0e56f0f

Please sign in to comment.