mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
When using an Entity column transformer for an object type, the underlying database column may be sortable, despite the static TypeScript type being an object. The `FindOptionsOrder` typing should allow sorting on that object property and not require further nesting. Fixes issue #9895.
This commit is contained in:
parent
07221a3646
commit
0814970a9c
@ -24,7 +24,7 @@ export type FindOptionsOrderProperty<Property> = Property extends Promise<
|
||||
: Property extends ObjectID
|
||||
? FindOptionsOrderValue
|
||||
: Property extends object
|
||||
? FindOptionsOrder<Property>
|
||||
? FindOptionsOrder<Property> | FindOptionsOrderValue
|
||||
: FindOptionsOrderValue
|
||||
|
||||
/**
|
||||
|
||||
31
test/github-issues/9895/entity/ExampleEntity.ts
Normal file
31
test/github-issues/9895/entity/ExampleEntity.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { Entity } from "../../../../src/decorator/entity/Entity"
|
||||
import { Column } from "../../../../src/decorator/columns/Column"
|
||||
import { PrimaryGeneratedColumn } from "../../../../src/decorator/columns/PrimaryGeneratedColumn"
|
||||
|
||||
class ExampleBigNumber {
|
||||
constructor(private value: string) {}
|
||||
|
||||
toFixed() {
|
||||
return this.value
|
||||
}
|
||||
}
|
||||
|
||||
@Entity()
|
||||
export class ExampleEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Column({
|
||||
type: "numeric",
|
||||
nullable: false,
|
||||
transformer: {
|
||||
from: (value: any): ExampleBigNumber => {
|
||||
return new ExampleBigNumber(value)
|
||||
},
|
||||
to: (value: any): string => {
|
||||
return value.toFixed()
|
||||
},
|
||||
},
|
||||
})
|
||||
total: ExampleBigNumber
|
||||
}
|
||||
33
test/github-issues/9895/issue-9895.ts
Normal file
33
test/github-issues/9895/issue-9895.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { DataSource } from "../../../src"
|
||||
import {
|
||||
closeTestingConnections,
|
||||
createTestingConnections,
|
||||
reloadTestingDatabases,
|
||||
} from "../../utils/test-utils"
|
||||
import { ExampleEntity } from "./entity/ExampleEntity"
|
||||
|
||||
describe("github issues > #9895", () => {
|
||||
let dataSources: DataSource[]
|
||||
|
||||
before(async () => {
|
||||
dataSources = await createTestingConnections({
|
||||
entities: [ExampleEntity],
|
||||
enabledDrivers: ["postgres"],
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(() => reloadTestingDatabases(dataSources))
|
||||
after(() => closeTestingConnections(dataSources))
|
||||
|
||||
it("should allow find order on object property", async () => {
|
||||
await Promise.all(
|
||||
dataSources.map(async (dataSource) => {
|
||||
await dataSource.manager.find(ExampleEntity, {
|
||||
order: {
|
||||
total: "DESC",
|
||||
},
|
||||
})
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user