sequelize / website

Our beloved website that contains all versions of our documentations and the API references.
https://sequelize.org
29 stars 154 forks source link

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

Open kirill-ianchuk opened 2 years ago

kirill-ianchuk commented 2 years ago

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);
WikiRik commented 2 years ago

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!