website icon indicating copy to clipboard operation
website copied to clipboard

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

Open kirill-ianchuk opened this issue 3 years ago • 1 comments

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);

kirill-ianchuk avatar Apr 14 '22 06:04 kirill-ianchuk

I transferred this to the website repo, where we store the documentation files. Thanks for the suggestion, we'll take a look at it soon!

WikiRik avatar Apr 14 '22 06:04 WikiRik