Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection loadCount() throws error: Trying to query by not existing property Class.undefined #1608

Closed
ps-amaureder opened this issue Mar 25, 2021 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@ps-amaureder
Copy link

Describe the bug
When using an unidirectional ManyToMany Collection, calling the function loadCount() on that Collection throws an error if the Collection is not initialized

Stack trace

Error: Trying to query by not existing property Class.undefined
      at /..../node_modules/@mikro-orm/knex/query/CriteriaNode.js:21:27
      at Array.forEach (<anonymous>)
      at new CriteriaNode (/..../node_modules/@mikro-orm/knex/query/CriteriaNode.js:18:48)
      at new ScalarCriteriaNode (/..../node_modules/@mikro-orm/knex/query/ScalarCriteriaNode.js:6:1)
      at Function.createScalarNode (/..../node_modules/@mikro-orm/knex/query/CriteriaNodeFactory.js:22:22)
      at Function.createNode (/..../node_modules/@mikro-orm/knex/query/CriteriaNodeFactory.js:19:21)
      at Function.createObjectItemNode (/..../node_modules/@mikro-orm/knex/query/CriteriaNodeFactory.js:47:25)
      at /..../node_modules/@mikro-orm/knex/query/CriteriaNodeFactory.js:38:28
      at Array.reduce (<anonymous>)
      at Function.createObjectNode (/..../node_modules/@mikro-orm/knex/query/CriteriaNodeFactory.js:37:45)
      at Function.createNode (/..../node_modules/@mikro-orm/knex/query/CriteriaNodeFactory.js:17:25)
      at QueryBuilder.where (/..../node_modules/@mikro-orm/knex/query/QueryBuilder.js:116:72)
      at PostgreSqlDriver.count (/..../node_modules/@mikro-orm/knex/AbstractSqlDriver.js:139:14)
      at SqlEntityManager.count (/..../node_modules/@mikro-orm/core/EntityManager.js:409:41)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)
      at Collection.loadCount (/..../node_modules/@mikro-orm/core/entity/Collection.js:67:31)

To Reproduce
Steps to reproduce the behavior:

  1. Create an unidirectional ManyToMany Collection
  2. call the loadCount() function on the Collection (collection must not be initialized)

Expected behavior
The number of items should be returned

Additional context

@ManyToMany({ entity: () => Class, fixedOrder: true })
field: Collection<Class> = new Collection<Class>(this);

When the Collection is initialized it works fine
When using a bidirectional ManyToMany Collection it works fine

Versions
| Dependency | Version |
| node | 14.15.4 |
| typescript | 4.0.5 |
| mikro-orm/core | 4.5.0 |
| mikro-orm/migrations | 4.5.0 |
| mikro-orm/nestjs | 4.2.0 |
| mikro-orm/postgresql | 4.5.0 |

@B4nan B4nan added the bug Something isn't working label Mar 25, 2021
@B4nan B4nan closed this as completed in 27e4dd2 Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants