Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daisuke-fukuda/4f6c0b3c8bc39433e1c2fa27fda0764e to your computer and use it in GitHub Desktop.
Save daisuke-fukuda/4f6c0b3c8bc39433e1c2fa27fda0764e to your computer and use it in GitHub Desktop.
typeORMのissue下書き
**Issue type:**
[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue
**Database system/driver:**
[ ] `cordova`
[ ] `mongodb`
[ ] `mssql`
[ ] `mysql` / `mariadb`
[ ] `oracle`
[x] `postgres`
[ ] `cockroachdb`
[ ] `sqlite`
[ ] `sqljs`
[ ] `react-native`
[ ] `expo`
**TypeORM version:**
[ ] `latest`
[ ] `@next`
[ ] `0.x.x` (or put your version here)
**Steps to reproduce or a small repository showing the problem:**
***entity:***
```
@Entity('some_table')
export class SomeTable {
@PrimaryColumn('text', { name: 'string_key' })
stringKey!: string;
@PrimaryColumn('timestamptz', { name: 'timestamptz_key' })
timestamptzKey!: Date;
@Column('text', { name: 'content' })
content!: string;
}
```
***call getMany:***
```
export class CustomRepository {
constructor(private manager: EntityManager) {}
async get(): Promise<SomeTable[]> {
const eventEntities = await this.manager
.getRepository(SomeTable)
.createQueryBuilder('some_table')
.getMany();
}
}
```
***data:***
|string_key |timestamptz_key| content|
|-----------|---------------|---------
|aaa |2020-05-18 07:42:29.392000 +00:00 |some1|
|aaa |2020-05-18 07:42:29.678000 +00:00 |some2|
***result:***
only return one row.
***why:***
https://github.com/typeorm/typeorm/blob/d7256c710ec6b4fdecdced002d77eb03417fbc96/src/query-builder/transformer/RawSqlResultsToEntityTransformer.ts#L65
In this section, grouping rows via join primary key value as string.
If column is `Timestamp` type, toString method (which called Implicitly by `join("_")`) truncate omit milli second.
like this.
```
const now = new Date();
console.log(now);
Tue May 19 2020 12:31:20 GMT+0900
```
@enzinia
Copy link

enzinia commented May 21, 2020

67: maybe better to use different key?
72: I think better to put this row, that returned
79: truncate millisecondsかな

other looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment