You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Relations two levels deep are not selected if there parent already exists in the identity map when using the query builder.
To Reproduce
import{Collection,Entity,ManyToOne,OneToMany,PrimaryKey,}from'@mikro-orm/core';import{MikroORM}from'@mikro-orm/sqlite';
@Entity()exportclassUser{
@PrimaryKey()id!: string;
@OneToMany(()=>Post,post=>post.user)posts=newCollection<Post>(this);}
@Entity()exportclassPost{
@PrimaryKey()id!: string;
@OneToMany(()=>Comment,comment=>comment.post)comments=newCollection<Comment>(this);
@ManyToOne()user: User;}
@Entity()classComment{
@PrimaryKey()id!: string;
@ManyToOne()post: Post;}letorm: MikroORM;beforeAll(async()=>{orm=awaitMikroORM.init({dbName: ':memory:',entities: [Comment,Post,User],});awaitorm.schema.refreshDatabase();});afterAll(()=>orm.close(true));beforeEach(async()=>{constfork=orm.em.fork();awaitorm.schema.clearDatabase();fork.create(User,{id: 'user1',});fork.create(Post,{id: 'post1',user: 'user1',});fork.create(Comment,{id: 'comment',post: 'post1',});awaitfork.flush();});test('it should select comments even if posts have already been selected',async()=>{constfork=orm.em.fork();awaitfork.qb(Post).select('*');constusers=awaitfork.qb(User).select('*').joinAndSelect('posts','p').leftJoinAndSelect('p.comments','c');expect(users[0].posts[0].comments[0]).toBeDefined();});//This one works without the initial await fork.qb(Post).select('*');test('it should select comments even if posts have already been selected',async()=>{constfork=orm.em.fork();constusers=awaitfork.qb(User).select('*').joinAndSelect('posts','p').leftJoinAndSelect('p.comments','c');expect(users[0].posts[0].comments[0]).toBeDefined();});
Expected behavior
Comments are returned as a child of posts
Versions
Dependency
Version
node
16.19.1
typescript
4.7.4
mikro-orm
5.6.15
The text was updated successfully, but these errors were encountered:
Describe the bug
Relations two levels deep are not selected if there parent already exists in the identity map when using the query builder.
To Reproduce
Expected behavior
Comments are returned as a child of posts
Versions
The text was updated successfully, but these errors were encountered: