I'm attempting to establish a connection between two models while adding an additional property called "url":
if (typeof session.id === "number") {
const sessionUser = await Session.relatedQuery("users")
.for(session.id)
.relate({
id: 12345, // encountering error here
url: "test",
});
}
The typescript error message I'm receiving is:
Argument of type '{ id: number; url: string; }' is not assignable to parameter of type 'string | number | CompositeId | MaybeCompositeId[] | PartialModelObject | PartialModelObject[]'. Object literal may only specify known properties, and 'id' does not exist in type 'CompositeId | MaybeCompositeId[] | PartialModelObject | PartialModelObject[]'.
However, when I attempt to relate the models without the extra property, it runs smoothly:
if (typeof session.id === "number") {
const sessionUser = await Session.relatedQuery("users")
.for(session.id)
.relate(userId); //userId is simply a number e.g. 5
}
Below is my Session model. I have also added the extra property on my User model as a precaution:
export class Session extends Model {
host_id?: number;
url?: string;
static get tableName() {
return "sessions";
}
static relationMappings = {
users: {
relation: Model.ManyToManyRelation,
modelClass: path.join(__dirname, "User"),
join: {
from: "sessions.id",
through: {
from: "sessions_users.session_id",
to: "sessions_users.user_id",
extra: ["url"],
},
to: "users.id",
},
},
};
}
Here are the resources regarding extra properties:
Is there something obvious that I might be overlooking?