| 475 | } |
| 476 | |
| 477 | func TestSelectWithUpdateColumn(t *testing.T) { |
| 478 | user := *GetUser("select_with_update_column", Config{Account: true, Pets: 3, Toys: 3, Company: true, Manager: true, Team: 3, Languages: 3, Friends: 4}) |
| 479 | DB.Create(&user) |
| 480 | |
| 481 | updateValues := map[string]interface{}{"Name": "new_name", "Age": 50} |
| 482 | |
| 483 | var result User |
| 484 | DB.First(&result, user.ID) |
| 485 | |
| 486 | time.Sleep(time.Second) |
| 487 | lastUpdatedAt := result.UpdatedAt |
| 488 | DB.Model(&result).Select("Name").Updates(updateValues) |
| 489 | |
| 490 | var result2 User |
| 491 | DB.First(&result2, user.ID) |
| 492 | |
| 493 | if lastUpdatedAt.Format(time.RFC3339Nano) == result2.UpdatedAt.Format(time.RFC3339Nano) { |
| 494 | t.Errorf("UpdatedAt should be changed") |
| 495 | } |
| 496 | |
| 497 | if result2.Name == user.Name || result2.Age != user.Age { |
| 498 | t.Errorf("Should only update users with name column") |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | func TestOmitWithUpdateColumn(t *testing.T) { |
| 503 | user := *GetUser("omit_with_update_column", Config{Account: true, Pets: 3, Toys: 3, Company: true, Manager: true, Team: 3, Languages: 3, Friends: 4}) |