fix(utils): Typecasting non-text fields in FTS (#12729)
This commit is contained in:
@@ -4,7 +4,7 @@ import type {
|
||||
FindOneOptions,
|
||||
FindOptions,
|
||||
} from "@mikro-orm/core"
|
||||
import { EntityMetadata, ReferenceKind } from "@mikro-orm/core"
|
||||
import { EntityMetadata, raw, ReferenceKind } from "@mikro-orm/core"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
export const FreeTextSearchFilterKeyPrefix = "freeTextSearch_"
|
||||
@@ -54,9 +54,10 @@ function retrieveRelationsConstraints(
|
||||
}
|
||||
|
||||
const isText = propertyConfiguration?.columnTypes?.includes("text")
|
||||
|
||||
const columnName = isText
|
||||
? propertyConfiguration.name
|
||||
: `${propertyConfiguration.name}::text`
|
||||
: raw((alias) => `cast(${alias}.${propertyConfiguration.name} as text)`)
|
||||
|
||||
relationFreeTextSearchWhere.push({
|
||||
[columnName]: {
|
||||
|
||||
@@ -8,7 +8,10 @@ import { PrimaryKeyModifier } from "./primary-key"
|
||||
export class AutoIncrementProperty extends BaseProperty<number> {
|
||||
protected dataType: {
|
||||
name: "serial"
|
||||
options: {}
|
||||
options: {
|
||||
searchable?: boolean
|
||||
primaryKey?: boolean
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,6 +33,27 @@ export class AutoIncrementProperty extends BaseProperty<number> {
|
||||
return new PrimaryKeyModifier<number, AutoIncrementProperty>(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* This method indicates that a serial property is searchable.
|
||||
*
|
||||
* @example
|
||||
* import { model } from "@medusajs/framework/utils"
|
||||
*
|
||||
* const MyCustom = model.define("my_custom", {
|
||||
* name: model.autoincrement().searchable(),
|
||||
* // ...
|
||||
* })
|
||||
*
|
||||
* export default MyCustom
|
||||
*
|
||||
* @customNamespace Property Configuration Methods
|
||||
*/
|
||||
searchable() {
|
||||
this.dataType.options.searchable = true
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
constructor(options?: { primaryKey?: boolean }) {
|
||||
super()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user