-
-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(mikro): infinite loop when using OneToOne eager loading #546
Conversation
one small issue I found out, if I have an entity @Entity()
export class Series extends Base {
@OneToMany(() => SeriesPost, (seriesPost) => seriesPost.series)
seriesPosts = new Collection<SeriesPost>(this);
@AutoMap()
@Property({ persist: false })
get chapterNumbers() {
if (!this.seriesPosts.isInitialized()) {
return 0;
}
return this.seriesPosts.length;
}
} when automapper runs, it will ignore the if (!Utils.isEntity(item)) return item;
if (toPojo) return wrap(item).toPOJO(); If we always returns When I use |
for version 6, we can do const keys = Object.keys((wrap(item) as IWrappedEntityInternal<AnyEntity>).__meta.properties); instead of Reflect.ownKeys(item) When using |
Version 5 of MikroORM is also facing this issue. We're facing the exact same issue as @zgid123, did you happen to find any work around to use until this gets merged? |
@toonvanstrijp currently I copy my fix to my repo and then import from that file instead of using the |
Kudos, SonarCloud Quality Gate passed! |
@toonvanstrijp FYI: I created a temporary package while waiting for the author here. I tested with my project and worked |
Thanks @zgid123 for the PR |
* fix(mikro): infinite loop when using OneToOne eager loading * fix(mikro): mapping custom property of mikro entity to automapper
I am using Mikro version
6.0.0-dev.75
, I am not sure if version5
face this issue or not. But I think it faces the same issue.My usage is I have two models with
OneToOne
association, when eager loading,mikro-orm
will load the model asreference
, and thenautomapper
will callserializeEntity
infinitely.Example:
In controller, I use
It will cause infinite loop because
post.seriesPost.post
is areference
ofpost
.The main idea of the fix is memorized the
POJO
/raw entity
of themikro-orm
, then when we have a cycle, we will get from memorized instead of calling theserializeEntity
.Currently, when I do
I cannot get the data of
seriesPost.post
, my project does not need that, but I still not know why it does not get that property. Maybe my config is wrong. I will test it later and will have a fix for this case (if it is a bug)