Collection ordered wrong on 1:N relationship with eager loading
See original GitHub issueIssue type: [X] question [?] bug report
Database system/driver:
[X] mysql
/ mariadb
TypeORM version:
[X] 0.2.6
(or put your version here)
I got a little problem working with typeorm.
Now I am trying to find a record using findOne(entityId)
method.
My table have 1:N relationship. For example,
class User {
@PrimaryColumn()
id: string
@OneToMany(() => UserSignInLog, (userSignInLog: UserSignInLog) => userSignInLog.user, {
cascade: true,
eager: true
})
signInLogs: UserSignInLog[]
}
class UserSignInLog {
@PrimaryColumn({ })
id: string
@ManyToOne(() => User, (user: User) => user.signInLogs, {
onDelete: 'CASCADE'
})
@JoinColumn({ name: 'userId'})
user: User;
}
- Consider entity specification can be quite wrong because of sample.
The problem is, when I load user and all of the its signIn logs, that the SignInlogs are not ordered correctly as I inserted.
I read all of query logs of my database, and tried to execute same queries which are logged. The query results are not ordered correctly same as the results of findOne
method.
Some results are ordered fine, the others are ordered wrong: like, ‘B’ shows up after ‘A’ when it should be ‘A’ after ‘B’.
So, My question is,
- Is there any options to set or change order when loading all collection using eager loading?
If not, in my humble opinion, it is not a code-level problem, so I hope you to check the your query builder when findOne
method executes. All data recorded as I wanted, only findOne
returns wrong result.
Thanks!
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
This was exactly what I was searching the docs for. Seemed logical to me to have an order option for relations.
Then I’ll have to use the querybuilder…
but in query builder you are explicit and you can set any order you want.
Here we can add another option like
eagerOrder
, but Im not sure if I want to add another complexity.