-
-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sqlite): fix mapping of joined results with
DateTimeType
proper…
…ties Closes #5550
- Loading branch information
Showing
2 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { Collection, Entity, ManyToOne, MikroORM, OneToMany, PrimaryKey, Property, t } from '@mikro-orm/sqlite'; | ||
|
||
@Entity() | ||
class User { | ||
|
||
@PrimaryKey({ type: t.integer }) | ||
id!: number; | ||
|
||
@Property({ type: t.string }) | ||
fullName!: string; | ||
|
||
@Property({ type: t.datetime }) | ||
tdatetime: Date; | ||
|
||
@Property({ type: 'datetime' }) | ||
qdatetime: Date; | ||
|
||
@Property({ type: 'Date' }) | ||
qDate: Date; | ||
|
||
@Property({ type: Date }) | ||
Date: Date; | ||
|
||
@OneToMany(() => Article, (article: Article) => article.author) | ||
articles = new Collection<Article>(this); | ||
|
||
constructor(fullName: string, date: Date) { | ||
this.fullName = fullName; | ||
this.tdatetime = date; | ||
this.qdatetime = date; | ||
this.qDate = date; | ||
this.Date = date; | ||
} | ||
|
||
} | ||
|
||
@Entity() | ||
class Article { | ||
|
||
@PrimaryKey({ type: t.integer }) | ||
id!: number; | ||
|
||
@Property({ type: t.string }) | ||
title: string; | ||
|
||
@Property({ type: t.datetime }) | ||
tdatetime: Date; | ||
|
||
@Property({ type: 'datetime' }) | ||
qdatetime: Date; | ||
|
||
@Property({ type: 'Date' }) | ||
qDate: Date; | ||
|
||
@Property({ type: Date }) | ||
Date: Date; | ||
|
||
@ManyToOne(() => User) | ||
author: User; | ||
|
||
constructor(author: User, title: string, date: Date) { | ||
this.author = author; | ||
this.title = title; | ||
this.tdatetime = date; | ||
this.qdatetime = date; | ||
this.qDate = date; | ||
this.Date = date; | ||
} | ||
|
||
} | ||
|
||
let orm: MikroORM; | ||
|
||
beforeAll(async () => { | ||
orm = await MikroORM.init({ | ||
entities: [User], | ||
dbName: `:memory:`, | ||
}); | ||
await orm.schema.refreshDatabase(); | ||
}); | ||
|
||
afterAll(() => orm.close(true)); | ||
|
||
test('5550', async () => { | ||
const user = new User('Foo Bar', new Date()); | ||
user.articles.add(new Article(user, 'hello world', new Date())); | ||
await orm.em.persist(user).flush(); | ||
const dbUser = await orm.em.fork().findOne(User, { id: 1 }, { populate: ['articles'] }); | ||
expect(dbUser).toMatchObject({ | ||
tdatetime: expect.any(Date), | ||
qdatetime: expect.any(Date), | ||
qDate: expect.any(Date), | ||
Date: expect.any(Date), | ||
id: 1, | ||
}); | ||
expect(dbUser?.articles[0]).toMatchObject({ | ||
title: 'hello world', | ||
tdatetime: expect.any(Date), | ||
qdatetime: expect.any(Date), | ||
qDate: expect.any(Date), | ||
Date: expect.any(Date), | ||
author: expect.any(User), | ||
id: 1, | ||
}); | ||
}); |