Skip to content

Commit 8d3f892

Browse files
committed
fix: fix issue with references not working properly without setting RelationId
1 parent fb43c32 commit 8d3f892

File tree

4 files changed

+5
-16
lines changed

4 files changed

+5
-16
lines changed

src/Property.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ export class Property extends BaseProperty {
88
private columnPosition: number;
99

1010
constructor(column: ColumnMetadata, columnPosition = 0) {
11-
// for reference fields take database name (with ...Id)
12-
const path = column.referencedColumn ? column.databaseName : column.propertyPath
11+
const path = column.propertyPath
1312
super({ path })
1413
this.column = column
1514
this.columnPosition = columnPosition

src/Resource.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,8 @@ export class Resource extends BaseResource {
152152
if (param === null) {
153153
preparedParams[property.column.propertyName] = null
154154
} else {
155-
// references cannot be stored as an IDs in typeorm, so in order to mimic this) and
156-
// not fetching reference resource) change this:
157-
// { postId: "1" }
158-
// to that:
159-
// { post: { id: 1 } }
160155
const id = (property.column.type === Number) ? Number(param) : param
161-
preparedParams[property.column.propertyName] = { id }
156+
preparedParams[property.column.propertyName] = id
162157
}
163158
}
164159
})

src/utils/convertFilter.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,8 @@ export function convertFilter(filter?: Filter): FindConditions<BaseEntity> {
2626
} else if ((one.property as Property).column.type === 'enum') {
2727
where[n] = one.value
2828
} else if ((one.property as Property).type() === 'reference') {
29-
// when comes to reference TypeORM cannot filter by referenceId: YOUR_FILTER_VALUE
30-
// I don't know why. But it filters by an object: reference: {id: YOUR_FILTER_VALUE}
31-
// propertyPath holds `reference.id` that is why we split it by `.`
32-
const [column, key] = (one.property as Property).column.propertyPath.split('.')
33-
where[column] = {
34-
[key]: one.value,
35-
}
29+
const [column] = (one.property as Property).column.propertyPath.split('.')
30+
where[column] = one.value
3631
} else {
3732
where[n] = Like(`%${one.value}%`)
3833
}

src/utils/data-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const DATE = [
4343
// WithPrecisionColumnType:
4444
'datetime', 'datetime2', 'datetimeoffset', 'time', 'time with time zone',
4545
'time without time zone', 'timestamp', 'timestamp without time zone',
46-
'timestamp with time zone', 'timestamp with local time zone',
46+
'timestamp with time zone', 'timestamp with local time zone', 'timestamptz',
4747

4848
// SimpleColumnType:
4949
'timestamp with local time zone', 'smalldatetime', 'date',

0 commit comments

Comments
 (0)