Skip to content

createQueryBuilder relation remove works only if using ID #2632

@Kalhama

Description

@Kalhama

Issue type:

[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest (0.2.0)
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

I'm working with a backend where one organisation could have multiple admins (we call them coordinators). One user could be coordinating multiple organisations, so relation between is Many-to-many -relation.

I'm using queryBuilder to delete relations in a following way

const removeCoordinatorFromOrganisation = async (organisationId, userId) => {
  // userId means coordinator
  const organisation = await getConnection.getRepository(Organisation).findOneOrFail(organisationId)

  await this.organisation
    .createQueryBuilder()
    .relation('coordinators')
    .of(organisation)
    .remove(userId)

  const org = await this.organisation.findOneOrFail({
    where: { id: organisationId },
    relations: ['coordinators']
  })

  return org.coordinators
}

This doesn't remove relation unless I change the queryBuilder to use organisationId instead of organisation entity.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions