-
-
Notifications
You must be signed in to change notification settings - Fork 611
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
Sometimes, we get a Collection of entity not initialized error when loading the collection using loadItems
Error: Collection<Workspace> of entity QuorumQBFTBlockchainNetwork[66e18d930cc3ee508ce796dd] not initialized
at Collection.checkInitialized (/app/node_modules/@mikro-orm/core/entity/Collection.js:327:19)
at Collection.getItems (/app/node_modules/@mikro-orm/core/entity/Collection.js:108:18)
at /app/node_modules/@mikro-orm/core/entity/EntityLoader.js:454:40
at Array.reduce (<anonymous>)
at EntityLoader.getChildReferences (/app/node_modules/@mikro-orm/core/entity/EntityLoader.js:453:39)
at EntityLoader.findChildren (/app/node_modules/@mikro-orm/core/entity/EntityLoader.js:211:31)
at EntityLoader.populateMany (/app/node_modules/@mikro-orm/core/entity/EntityLoader.js:150:33)
at processTicksAndRejections (/Users/snigdhasingh/Development/btp/apps/api/lib/internal/process/task_queues.js:95:5)
at EntityLoader.populateField (/app/node_modules/@mikro-orm/core/entity/EntityLoader.js:287:27)
at EntityLoader.populate (/app/node_modules/@mikro-orm/core/entity/EntityLoader.js:57:13)
at MongoEntityManager.populate (/app/node_modules/@mikro-orm/core/EntityManager.js:1367:9)
at Collection.init (/app/node_modules/@mikro-orm/core/entity/Collection.js:248:9)
at Collection.load (/app/node_modules/@mikro-orm/core/entity/Collection.js:43:13)
at Collection.loadItems (/app/node_modules/@mikro-orm/core/entity/Collection.js:58:9)
at BlockchainNetworkResolver.canInviteWorkspaces (/app/src/modules/blockchain/api/lib/resolvers/blockchain-network.resolver.ts:106:14) {stack: 'Error: Collection<Workspace> of entity Quorum…olvers/blockchain-network.resolver.ts:106:14)', message: 'Collection<Workspace> of entity QuorumQBFTBl…rk[66e18d930cc3ee508ce796dd] not initialized'}
Reproduction
import {
Collection,
Entity,
ManyToMany,
MikroORM,
PrimaryKey,
Property,
ObjectId,
} from '@mikro-orm/mongodb';
@Entity()
class Manager {
@PrimaryKey()
_id!: ObjectId;
@ManyToMany({
entity: 'Task',
lazy: true,
})
tasks = new Collection<Task>(this);
}
@Entity()
class Task {
@PrimaryKey()
_id!: ObjectId;
@Property()
name!: string;
}
describe('GH issue 6079', () => {
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [Manager, Task],
dbName: ':memory:',
});
await orm.schema.createSchema();
const task = new Task();
task.name = 'task';
const manager = new Manager();
manager.tasks.set([task]);
await orm.em.persistAndFlush(manager);
orm.em.clear();
});
afterAll(() => orm.close(true));
test('owning side can intialize collections using loadItems', async () => {
const [manager] = await orm.em.findAll(Manager);
expect(manager.tasks.isInitialized()).toBe(false);
await manager.tasks.loadItems();
expect(manager.tasks.isInitialized()).toBe(true);
expect(manager.tasks).toHaveLength(1);
});
});What driver are you using?
@mikro-orm/mongodb
MikroORM version
6.3.11
Node.js version
22.9.0
Operating system
MacOS
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