Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork604
-
Describe the bugUsing eager relations with Failing query example Reproductionimport{Entity,LockMode,ManyToOne,MikroORM,OneToMany,PrimaryKey,Property}from'@mikro-orm/postgresql';@Entity()classUser2{ @PrimaryKey()id!:number; @Property()surname!:string}@Entity()classUser{ @PrimaryKey()id!:number; @Property()name:string; @Property({unique:true})email:string; @ManyToOne(()=>User2,{eager:true})secondUser!:User2constructor(name:string,email:string){this.name=name;this.email=email;}}letorm:MikroORM;beforeAll(async()=>{orm=awaitMikroORM.init(...);awaitorm.schema.refreshDatabase();});afterAll(async()=>{awaitorm.close(true);});test('basic CRUD example',async()=>{orm.em.create(User,{name:'Foo',email:'foo',secondUser:{surname:'test'}});awaitorm.em.flush();orm.em.clear();constf=orm.em.fork()awaitf.begin()constuser=awaitf.findOneOrFail(User,{email:'foo'},{lockMode:LockMode.PESSIMISTIC_WRITE});}); What driver are you using?@mikro-orm/postgresql MikroORM version6.4.3 Node.js version. Operating systemNo response Validations
|
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 5 comments
-
The problem is your populated relation, you need to lock only the root table via lockTableAliases option. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Huh. My bad, missed that. |
BetaWas this translation helpful?Give feedback.
All reactions
-
The support right now is not perfect, I'd like to provide something like |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
My current workaround looks like this: constuser=awaitdb.findOneOrFail(User,{id:1})awaitdb.lock(user,LockMode.PESSIMISTIC_WRITE) It generates 2 queries, but w/e - it seems to work fine. Now that I think about it, I feel like just locking the main table ( |
BetaWas this translation helpful?Give feedback.
All reactions
-
Next version will skip left-joined tables from pessimistic locking automatically:ffb71a1 |
BetaWas this translation helpful?Give feedback.
All reactions
This discussion was converted from issue #6411 on February 12, 2025 11:16.