File tree 1 file changed +14
-11
lines changed
1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -655,25 +655,28 @@ func (s *Product8) BeforeFind(tx *gorm.DB) error {
655
655
return nil
656
656
}
657
657
658
- // Fails for postgres
659
- // ERROR: invalid input syntax for type bigint: "t" (SQLSTATE 22P02)
660
658
func TestBeforeFindModifiesQuery (t * testing.T ) {
661
659
DB .Migrator ().DropTable (& Product8 {})
662
660
DB .AutoMigrate (& Product8 {})
663
661
664
- products := []Product8 {
665
- {Code : "A" , Price : 100 },
666
- {Code : "B" , Price : 30 },
662
+ p1 := Product8 {Code : "A" , Price : 30 }
663
+ DB .Create (& p1 )
664
+
665
+ var result Product8
666
+
667
+ DB .Find (& result )
668
+
669
+ if (result != Product8 {}) {
670
+ t .Errorf ("BeforeFind should filter results, got %v" , result )
667
671
}
668
- DB .Create (& products )
669
672
670
- var results []Product8
673
+ p2 := Product8 {Code : "B" , Price : 100 }
674
+ DB .Create (& p2 )
671
675
672
- // Without condition, hooks will be skipped
673
- DB .Find (& results , true )
676
+ DB .Find (& result )
674
677
675
- if len ( results ) != 1 || results [ 0 ] .Code != "A " {
676
- t .Errorf ("BeforeFind should filter results, got %v" , results )
678
+ if result .Code != "B " {
679
+ t .Errorf ("BeforeFind should filter results, got %v" , result )
677
680
}
678
681
}
679
682
You can’t perform that action at this time.
0 commit comments