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

ManyToMany and Custom Typed PK #1930

Closed
mastercoding opened this issue Jun 14, 2021 · 0 comments
Closed

ManyToMany and Custom Typed PK #1930

mastercoding opened this issue Jun 14, 2021 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@mastercoding
Copy link

Describe the bug
When using a custom typed PK (see #1798), ManyToMany using a pivotTable doesn't work. The map returned from

await this.driver.loadFromPivotTable()

does not contain converted keys and thus the lookup fails.

map[entity.__helper.getSerializedPrimaryKey()] 

is undefined.

Stacktrace

TypeError: Cannot read property 'map' of undefined
    at EntityLoader.findChildrenFromPivotTable (/app/node_modules/@mikro-orm/core/entity/EntityLoader.js:232:69)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async EntityLoader.populateField (/app/node_modules/@mikro-orm/core/entity/EntityLoader.js:185:25)
    at async EntityLoader.populate (/app/node_modules/@mikro-orm/core/entity/EntityLoader.js:37:13)
    at async EntityLoader.populateField (/app/node_modules/@mikro-orm/core/entity/EntityLoader.js:203:9)
    at async EntityLoader.populate (/app/node_modules/@mikro-orm/core/entity/EntityLoader.js:37:13)
    at async SqlEntityManager.find (/app/node_modules/@mikro-orm/core/EntityManager.js:105:9)
    at async EntityLoader.populateMany (/app/node_modules/@mikro-orm/core/entity/EntityLoader.js:127:22)
    at async EntityLoader.populateField (/app/node_modules/@mikro-orm/core/entity/EntityLoader.js:187:9)
    at async EntityLoader.populate (/app/node_modules/@mikro-orm/core/entity/EntityLoader.js:37:13)

To Reproduce
Steps to reproduce the behavior:

Create the entities with the custom type from #1798.

export class Product {
  @PrimaryKey({ type: UuidBinaryType, name: 'uuid' })
  id: string;

 @ManyToMany({
    owner: true,
    entity: () => Field,
    pivotTable: 'product_order_field',
    joinColumn: 'product_id',
    inverseJoinColumn: 'order_field_id',
  })
  fields: Collection<Field> = new Collection<Field>(this);
}

export class Field {
  @PrimaryKey({ type: UuidBinaryType, name: 'uuid' })
  id: string;

  @Property()
  title: string;
}

  1. Fetch products with its fields from the database.

Versions

Dependency Version
node 14.16.1
typescript 4.2.3
@mikro-orm/core 4.5.6
@mikro-orm/mysql 4.5.6
@mikro-orm/nestjs 4.2.0
@B4nan B4nan added the bug Something isn't working label Jun 18, 2021
@B4nan B4nan closed this as completed in 3cdc786 Jun 19, 2021
B4nan added a commit that referenced this issue Jun 29, 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