Open kirill-ianchuk opened 2 years ago
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.
HomeTeam
AwayTeam
team.getHomeTeam()
To change the aliases to HomeGame and AwayGame:
HomeGame
AwayGame
Team.hasOne(Game, { as: 'HomeGame', foreignKey: 'homeTeamId' }); Team.hasOne(Game, { as: 'AwayGame', foreignKey: 'awayTeamId' }); Game.belongsTo(Team);
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!
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:
If I define
HomeTeam
andAwayTeam
aliases, then, for instance, to fetch the team's home game using lazy loading I need to callteam.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
andAwayGame
: