Skip to content

Misleading aliases in "Multiple associations involving the same models" documentation #87

@kirill-ianchuk

Description

@kirill-ianchuk

Issue Creation Checklist

Issue Description

What was unclear/insufficient/not covered in the documentation

I suspect that Chapter Multiple associations involving the same models contains misleading examples of association aliases:

Team.hasOne(Game, { as: 'HomeTeam', foreignKey: 'homeTeamId' });
Team.hasOne(Game, { as: 'AwayTeam', foreignKey: 'awayTeamId' });
Game.belongsTo(Team);

If I define HomeTeam and AwayTeam aliases, then, for instance, to fetch the team's home game using lazy loading I need to call team.getHomeTeam(). This doesn't make sense to me.

If possible: Provide some suggestion on how we can enhance the docs

To change the aliases to HomeGame and AwayGame:

Team.hasOne(Game, { as: 'HomeGame', foreignKey: 'homeTeamId' });
Team.hasOne(Game, { as: 'AwayGame', foreignKey: 'awayTeamId' });
Game.belongsTo(Team);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions