-
-
Notifications
You must be signed in to change notification settings - Fork 34
Open
Description
Describe the bug
After updating the MikroORM package from version 6.4.5 to 6.4.7 it doesn't respect the schema in the relation tables.
When using this code:
async getOccupantByUserUuid(uuid: string): Promise<Occupant> {
const user = await this.em.findOne(
User,
{ uuid: uuid },
{ populate: ['occupant_uuid', 'institution', 'institution.uuid'], schema: 'schoolid' },
);
if (!user) throw new _NotFoundException('No user was found');
const occupant = await this.em.findOne(
Occupant,
{ uuid: user.occupant_uuid },
{ populate: ['roles.permissions'], schema: user.institution.uuid },
);
if (!occupant) throw new _NotFoundException('No occupant was found');
return occupant;
}
Specifically this part:
const occupant = await this.em.findOne(
Occupant,
{ uuid: user.occupant_uuid },
{ populate: ['roles.permissions'], schema: user.institution.uuid },
);
it ignores the schema for the relations as seen in this error message:
[Nest] 22152 - 02.03.2025, 23:19:54 ERROR [ExceptionsHandler] TableNotFoundException: select "o0"."uuid", "r1"."uuid" as "r1__uuid", "r1"."name" as "r1__name", "r1"."description" as "r1__description", "p3"."uuid" as "p3__uuid", "p3"."name" as "p3__name" from "7f3af19a-3028-426c-a267-cc9c1d77b766"."occupa
nt" as "o0" left join "7f3af19a-3028-426c-a267-cc9c1d77b766"."role_occupants" as "r2" on "o0"."uuid" = "r2"."occupant_uuid" left join "7f3af19a-3028-426c-a267-cc9c1d77b766"."role" as "r1" on "r2"."role_uuid" = "r1"."uuid" left join "role_permissions" as "r4" on "r1"."uuid" = "r4"."role_uuid" left join "schoolid"."permission" as "p3" on "r4"."permission_uuid" = "p3"."uuid" where "o0"."uuid" = '610c254b-c86a-4f61-8a66-b28edbafb3fb' - relation "role_permissions" does not exist
As seen for the role table it uses the specified schema:
"7f3af19a-3028-426c-a267-cc9c1d77b766"."role"
but not for the relation table:
"role_permissions"
As additional info here is the used Entity:
import { Collection, Entity, ManyToMany, Property } from '@mikro-orm/core';
import { _BaseEntityWithDates } from '../base';
import { Role } from './role.entity';
@Entity({ schema: '*' })
export class Occupant extends _BaseEntityWithDates {
@Property({ nullable: true, default: null, lazy: true })
studentId: string;
@ManyToMany(() => Role, role => role.occupants, { nullable: true })
roles: Collection<Role> = new Collection<Role>(this);
}
Reproduction
Reproduction seen as above. If more concrete Reproduction is needed feel free to ask!
What driver are you using?
@mikro-orm/postgresql
MikroORM version
6.4.7
Node.js version
v23.6.0
Operating system
Windows
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
No labels