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
When using QueryBuilder.update on an entity filtered by the non-owning side of a self-referential OneToOne mapping, the generated query is missing a join or subquery. It will fail with an error similar to:
update `book` set `title` = 'updatedTitle' where `b1`.`id` is null - Unknown column 'b1.id' in 'where clause'
To Reproduce
import{Entity,Property,PrimaryKey,Ref,OneToOne,OptionalProps,}from'@mikro-orm/core';import{MikroORM}from'@mikro-orm/mysql';
@Entity()exportclassBook{[OptionalProps]?: 'version';
@PrimaryKey()id!: string;
@OneToOne({entity: ()=>Book,inversedBy: 'sequel',ref: true,nullable: true})prequel?: Ref<Book>;
@OneToOne({entity: ()=>Book,mappedBy: 'prequel',ref: true,nullable: true})sequel?: Ref<Book>;
@Property()title!: string;}letorm: MikroORM;beforeAll(async()=>{orm=awaitMikroORM.init({dbName: 'mikro_orm_ghXXXX',entities: [Book],port: 3308,debug: true,});awaitorm.schema.refreshDatabase();});afterAll(()=>orm.close(true));test('unnamed',async()=>{constbook1=orm.em.create(Book,{id: 'book1',title: 'book1'});constbook2=orm.em.create(Book,{id: 'book2',title: 'book2',prequel: 'book1'});awaitorm.em.persistAndFlush([book1,book2]);orm.em.clear();constqb=orm.em.createQueryBuilder(Book);// This line fails with `update `book` set `title` = 'updatedTitle' where `b1`.`id` is null - Unknown column 'b1.id' in 'where clause'`awaitqb.update({title: 'updatedTitle'}).where({sequel: null});awaitorm.em.refresh(book1);awaitorm.em.refresh(book2);expect(book1.title).toEqual('book1');expect(book2.title).toEqual('updatedTitle');});
Expected behavior
The generated update query should either include a subquery or join on the table.
Versions
5.6.13 (and latest master)
Dependency
Version
node
18.5.0
typescript
4.9.0
mikro-orm
5.6.13
The text was updated successfully, but these errors were encountered:
Describe the bug
When using QueryBuilder.update on an entity filtered by the non-owning side of a self-referential OneToOne mapping, the generated query is missing a join or subquery. It will fail with an error similar to:
To Reproduce
Expected behavior
The generated update query should either include a subquery or join on the table.
Versions
5.6.13 (and latest
master
)The text was updated successfully, but these errors were encountered: