-
-
Notifications
You must be signed in to change notification settings - Fork 610
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
Em.count does not applies nested filters, when using OneToMany JOIN. Test in reproduction part should clearly show the problem.
- Using em.findAndCount, but same applies for em.count, which is called anyway
Related: Global filters are not applied on OneToMany JOIN clauses of where conditions #6458
Reproduction
import {
BaseEntity,
Collection,
Entity, Filter,
ManyToOne,
MikroORM,
OneToMany,
PrimaryKey,
DateTimeType,
Property,
OneToOne, Ref,
} from '@mikro-orm/sqlite';
@Entity({ abstract: true })
@Filter({
name: 'softDelete',
cond: {
deletedAt: null,
},
default: true,
})
export abstract class BE extends BaseEntity {
@PrimaryKey({ autoincrement: true })
readonly id!: string;
@Property({ type: DateTimeType, nullable: true })
deletedAt?: Date;
}
@Entity()
class A extends BE {
@Property()
title!: string;
@ManyToOne(() => B, { ref: true })
b!: Ref<B>;
}
@Entity()
class B extends BE {
@OneToMany(() => A, a => a.b)
a = new Collection<A>(this);
@OneToOne(() => C, c => c.b, {
ref: true,
})
c?: Ref<C>;
}
@Entity()
class C extends BE {
@OneToOne(() => B, { ref: true })
b?: Ref<B>;
}
describe('GH issue XXXX', () => {
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
dbName: ':memory:',
entities: [A, B, C],
});
});
afterAll(async () => {
await orm.close(true);
});
beforeEach(async () => {
await orm.schema.dropSchema();
await orm.schema.createSchema();
});
test('findAndCount: returned rows length and count should match', async () => {
const c1 = orm.em.create(C, {});
const c2 = orm.em.create(C, {});
const b1 = orm.em.create(B, { c: c1 });
const b2 = orm.em.create(B, { c: c2 });
const a1 = orm.em.create(A, { b: b1, title: 'test' });
const a2 = orm.em.create(A, { b: b2, title: 'test', deletedAt: new Date() });
await orm.em.flush();
orm.em.clear();
const [rows, count] = await orm.em.findAndCount(C, { b: { a: { title: 'test' } } });
expect(rows.length).toEqual(count);
});
});What driver are you using?
None
MikroORM version
6.4.15
Node.js version
20
Operating system
Mac OS
Validations
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working