Skip to content

Commit

Permalink
fix: preload all assocations
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Jun 17, 2024
1 parent 0224b57 commit 1a36504
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion adapters/gorm/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/google/uuid"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)

// RunMigrations is a helper function to run the migrations for the database.
Expand All @@ -18,6 +19,8 @@ func RunMigrations(db *gorm.DB) error {
&adapters.GothUser{},
&adapters.GothSession{},
&adapters.GothVerificationToken{},
&adapters.GothTeam{},
&adapters.GothRole{},
)
if err != nil {
return err
Expand Down Expand Up @@ -57,7 +60,7 @@ func (a *gormAdapter) CreateUser(ctx context.Context, user adapters.GothUser) (a
// GetSession is a helper function to retrieve a session by session token.
func (a *gormAdapter) GetSession(ctx context.Context, sessionToken string) (adapters.GothSession, error) {
var session adapters.GothSession
err := a.db.WithContext(ctx).Preload("User").Where("session_token = ?", sessionToken).First(&session).Error
err := a.db.WithContext(ctx).Preload(clause.Associations).Where("session_token = ?", sessionToken).First(&session).Error
if err != nil {
return adapters.GothSession{}, goth.ErrMissingSession
}
Expand Down

0 comments on commit 1a36504

Please sign in to comment.