.$add() returns Invalid Value {} when I pass it a Model as a second parameter.
clement-cavigniaux-inetum opened this issue · comments
Issue
When I use .$add or $set with a Model in second parameter, I have as return: Invalid value {}
Tell me if my code is the problem or not but I can't find anyone in the same case as me on StackOverflow...
Thanks in advance
Versions
- sequelize: ^6.30.0
- sequelize-typescript: ^2.1.5
- typescript: ^4.7.4
Issue type
- bug report
- feature request
Actual behavior
Expected behavior
Steps to reproduce
Related code
Service
const team: Teams = await this.teamModel.findByPk(id);
const member: User = await this.userService.findOneById(users[0]);
await team.$set('users', member); // return Invalid value {}
team.entity.ts
import { v4 as uuidv4 } from 'uuid'
import { Table, Column, Model, BelongsToMany, BelongsTo, DataType } from 'sequelize-typescript';
import User from 'src/user/entities/user.entity';
import UserTeams from './teamUsers.entity';
@Table({ timestamps: true })
export default class Teams extends Model {
@Column({ type: DataType.UUID, defaultValue: () => uuidv4(), primaryKey: true, unique: true, allowNull: false })
id: string;
@Column({ type: DataType.STRING, allowNull: false })
name: string;
//@BelongsTo(() => Projects, { foreignKey: 'id', as: 'project' })
@Column({ type: DataType.STRING, allowNull: false })
projectID: string;
@BelongsToMany(() => User, () => UserTeams)
users!: User[]
}
Go to TypeORM