-
-
Notifications
You must be signed in to change notification settings - Fork 43
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Environment
- Operating System: Linux
- Node Version: v20.12.0
- Package Manager: npm@10.5.0
- Builder: vite@5.0.8
- TypeScript Version: v5.2.2
- Pinia Version: v2.1.7
- Pinia ORM Version: v1.9.1
Reproduction
https://codesandbox.io/p/devbox/vue-3-ts-pinia-orm-2klhvr
Describe the bug
Since Version 1.9.0 a simple many-to-many relationship results in the following error when a namespace is defined:
Uncaught TypeError: this.schemas[related.entity] is undefined
This seems to happen only when a BelongsToMany relationship is defined. Please see the below example.
// BaseModel.ts
import { Model } from "pinia-orm";
export default abstract class BaseModel extends Model {
static entity: string;
static namespace: string = "orm";
}
// Role.ts
import BaseModel from "./BaseModel";
import { Str, Attr } from "pinia-orm/decorators";
export default class Role extends BaseModel {
@Attr()
declare id: number;
@Str(null)
declare name: string;
static entity: string = "roles";
}
// User.ts
import BaseModel from "./BaseModel";
import Role from "./Role";
import UserRole from "./UserRole";
import { Str, BelongsToMany, Attr } from "pinia-orm/decorators";
export default class User extends BaseModel {
@Attr()
declare id: number;
@Str(null)
declare name: string;
@BelongsToMany(() => Role, () => UserRole, "user_id", "role_id")
declare roles: Role[];
static entity: string = "users";
}
// UserRole.ts
import BaseModel from "./BaseModel";
import { Attr } from "pinia-orm/decorators";
export default class UserRole extends BaseModel {
@Attr()
declare user_id: number;
@Attr()
declare role_id: number;
static entity: string = "user_roles";
static primaryKey = ["user_id", "role_id"];
}
Additional context
No response
Logs
No response
CodeDredd
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working