Association fields are undefined and hold nothing.
Expected behavior
Association fields hold the database object corresponding to the foreign key.
Steps to reproduce
See related code.
Related code
import {
Column,
Default,
HasMany,
Model,
PrimaryKey,
Table,
} from 'sequelize-typescript';
import Player from './Player';
import Question from './Question';
@Table
class Room extends Model {
@PrimaryKey
@Column
roomNumber!: number;
@Default('')
@Column
name!: string;
@HasMany(() => Player)
players!: Player[];
@HasMany(() => Question)
questions!: Question[];
}
export default Room;
When accessing room.players after getting a room from the Database, it's considered undefined.
Same with any other kind of association.
Example:
I have the Session
import {
Column, DataType, Default, ForeignKey, HasOne, Model, PrimaryKey, Table,
} from 'sequelize-typescript';
import Player from './Player';
@Table
class Session extends Model {
@PrimaryKey
@Column(DataType.STRING)
socketId!: string;
@Column
playername!: string;
@Default(0)
@Column
avatarId!: number;
@HasOne(() => Player)
player!: Player;
@ForeignKey(() => Player)
@Column
playerId!: number;
}
export default Session;
Issue
Versions
Issue type
Actual behavior
Association fields are undefined and hold nothing.
Expected behavior
Association fields hold the database object corresponding to the foreign key.
Steps to reproduce
See related code.
Related code
When accessing room.players after getting a room from the Database, it's considered undefined. Same with any other kind of association. Example: I have the Session
And I have the player
The session is undefined, the room is undefined. The sessionId is NOT undefined. The roomNumber is also NOT undefined.