forked from jinzhu/gorm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Should ignore association conditions when querying with struct
- Loading branch information
Showing
2 changed files
with
19 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,24 @@ func TestFirstAndLast(t *testing.T) { | |
} | ||
} | ||
|
||
func TestQueryWithAssociation(t *testing.T) { | ||
user := &User{Name: "user1", Emails: []Email{{Email: "[email protected]"}}, Company: Company{Name: "company"}} | ||
|
||
if err := DB.Create(&user).Error; err != nil { | ||
t.Fatalf("errors happened when create user: %v", err) | ||
} | ||
|
||
user.CreatedAt = time.Time{} | ||
user.UpdatedAt = time.Time{} | ||
if err := DB.Where(&user).First(&User{}).Error; err != nil { | ||
t.Errorf("search with struct with association should returns no error, but got %v", err) | ||
} | ||
|
||
if err := DB.Where(user).First(&User{}).Error; err != nil { | ||
t.Errorf("search with struct with association should returns no error, but got %v", err) | ||
} | ||
} | ||
|
||
func TestFirstAndLastWithNoStdPrimaryKey(t *testing.T) { | ||
DB.Save(&Animal{Name: "animal1"}) | ||
DB.Save(&Animal{Name: "animal2"}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters