Posts

Showing posts with the label many-to-many

Querying database using 'with' and not getting the expected outcome

Image
Clash Royale CLAN TAG #URR8PPP Querying database using 'with' and not getting the expected outcome So I have two tables that share a many to many relationship: 1) Games , with info from matches created by users and Games 2) Users . Users Apart from the user/games relationship where a game belongs to many users and a user belongs to many games , there's also a relationship where a user can APPLY for many games and a game can BE APPLIED for by many users . For this relationship I created a junction table called requests . game users user games user games game users requests I'm using AdonisJs, so I set the model Games with Games applicants () { return this.belongsToMany( 'App/Models/User', 'game_id', 'applicant_id' ).pivotTable('requests') } and the model Users with Users applications () { return this.belongsToMany( 'App/Models/Game', 'applicant_id', 'game_id' ).pivotTable(...