forked from mirror/gorm
Add some tests for Related()
This commit is contained in:
parent
09c26cb387
commit
84395b435b
11
gorm_test.go
11
gorm_test.go
|
@ -1273,6 +1273,11 @@ func TestRelated(t *testing.T) {
|
|||
if len(emails) != 2 {
|
||||
t.Errorf("Should have two emails")
|
||||
}
|
||||
var user1 User
|
||||
db.Model(&user).Related(&user1.Emails)
|
||||
if len(user1.Emails) != 2 {
|
||||
t.Errorf("Should have two emails")
|
||||
}
|
||||
|
||||
var address1 Address
|
||||
db.Model(&user).Related(&address1, "BillingAddressId")
|
||||
|
@ -1280,6 +1285,12 @@ func TestRelated(t *testing.T) {
|
|||
t.Errorf("Should get billing address from user correctly")
|
||||
}
|
||||
|
||||
user1 = User{}
|
||||
db.Model(&address1).Related(&user1, "BillingAddressId")
|
||||
if db.NewRecord(user1) {
|
||||
t.Errorf("Should get user from address correctly")
|
||||
}
|
||||
|
||||
var user2 User
|
||||
db.Model(&emails[0]).Related(&user2)
|
||||
if user2.Id != user.Id || user2.Name != user.Name {
|
||||
|
|
Loading…
Reference in New Issue