Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 1,772 for user4 (0.04 sec)

  1. tests/upsert_test.go

    1. if user6.Name != "find or init" || user6.ID == 0 || user6.Age != 44 {
    2. t.Errorf("user should be found and updated with assigned attrs")
    3. }
    4. }
    5.  
    6. func TestFindOrCreate(t *testing.T) {
    7. var user1, user2, user3, user4, user5, user6, user7, user8 User
    8. if err := DB.Where(&User{Name: "find or create", Age: 33}).FirstOrCreate(&user1).Error; err != nil {
    9. t.Errorf("no error should happen when FirstOrInit, but got %v", err)
    10. }
    Registered: Sun Nov 03 09:35:10 UTC 2024
    - Last Modified: Mon Sep 05 07:39:19 UTC 2022
    - 11.4K bytes
    - Viewed (0)
  2. tests/update_has_many_test.go

    1. CheckUser(t, user2, user)
    2.  
    3. for idx := range user.Toys {
    4. user.Toys[idx].Name += "new"
    5. }
    6.  
    7. if err := DB.Save(&user).Error; err != nil {
    8. t.Fatalf("errors happened when update: %v", err)
    9. }
    10.  
    11. var user3 User
    12. DB.Preload("Toys").Find(&user3, "id = ?", user.ID)
    13. CheckUser(t, user2, user3)
    Registered: Sun Nov 03 09:35:10 UTC 2024
    - Last Modified: Thu Jan 06 07:02:53 UTC 2022
    - 2K bytes
    - Viewed (0)
  3. tests/preload_test.go

    1. }
    2.  
    3. var user4 *User
    4. DB.Preload("Pets.Toy").Find(&user4, "id = ?", user.ID)
    5. if len(user4.Pets) != 0 {
    6. t.Fatalf("User.Pet[0] was deleted and should not exist.")
    7. }
    8.  
    9. var user5 User
    10. DB.Unscoped().Preload(clause.Associations+"."+clause.Associations).Find(&user5, "id = ?", user.ID)
    11. CheckUserUnscoped(t, user5, user)
    12.  
    13. var user6 *User
    14. DB.Unscoped().Preload("Pets.Toy").Find(&user6, "id = ?", user.ID)
    Registered: Sun Nov 03 09:35:10 UTC 2024
    - Last Modified: Wed Jun 12 10:00:47 UTC 2024
    - 15.9K bytes
    - Viewed (0)
  4. tests/update_belongs_to_test.go

    1. var user2 User
    2. DB.Preload("Company").Preload("Manager").Find(&user2, "id = ?", user.ID)
    3. CheckUser(t, user2, user)
    4.  
    5. user.Company.Name += "new"
    6. user.Manager.Name += "new"
    7. if err := DB.Save(&user).Error; err != nil {
    8. t.Fatalf("errors happened when update: %v", err)
    9. }
    10.  
    11. var user3 User
    12. DB.Preload("Company").Preload("Manager").Find(&user3, "id = ?", user.ID)
    13. CheckUser(t, user2, user3)
    Registered: Sun Nov 03 09:35:10 UTC 2024
    - Last Modified: Thu Jul 14 06:55:54 UTC 2022
    - 1.6K bytes
    - Viewed (0)
  5. tests/update_many2many_test.go

    1. }
    2.  
    3. var user3 User
    4. DB.Preload("Languages").Preload("Friends").Find(&user3, "id = ?", user.ID)
    5. CheckUser(t, user2, user3)
    6.  
    7. if err := DB.Session(&gorm.Session{FullSaveAssociations: true}).Save(&user).Error; err != nil {
    8. t.Fatalf("errors happened when update: %v", err)
    9. }
    10.  
    11. var user4 User
    12. DB.Preload("Languages").Preload("Friends").Find(&user4, "id = ?", user.ID)
    13. CheckUser(t, user4, user)
    Registered: Sun Nov 03 09:35:10 UTC 2024
    - Last Modified: Thu Jan 06 07:02:53 UTC 2022
    - 1.3K bytes
    - Viewed (0)
  6. tests/update_has_one_test.go

    1. CheckUser(t, user2, user)
    2.  
    3. user.Account.Number += "new"
    4. if err := DB.Save(&user).Error; err != nil {
    5. t.Fatalf("errors happened when update: %v", err)
    6. }
    7.  
    8. var user3 User
    9. DB.Preload("Account").Find(&user3, "id = ?", user.ID)
    10.  
    11. CheckUser(t, user2, user3)
    12. lastUpdatedAt := user2.Account.UpdatedAt
    13. time.Sleep(time.Second)
    14.  
    15. if err := DB.Session(&gorm.Session{FullSaveAssociations: true}).Save(&user).Error; err != nil {
    Registered: Sun Nov 03 09:35:10 UTC 2024
    - Last Modified: Thu Jul 14 06:55:54 UTC 2022
    - 3.6K bytes
    - Viewed (0)
  7. tests/joins_test.go

    1. if user1.NamedPet == nil || user1.Account.ID == 0 {
    2. t.Fatalf("joins NamedPet and Account should not empty:%v", user1)
    3. }
    4.  
    5. // Account should empty
    6. DB.Delete(&user1.Account)
    7.  
    8. var user2 User
    9. DB.Model(&User{}).Joins("NamedPet").Joins("Account").First(&user2, user.ID)
    10. if user2.NamedPet == nil || user2.Account.ID != 0 {
    11. t.Fatalf("joins Account should not empty:%v", user2)
    12. }
    13.  
    14. // NamedPet should empty
    Registered: Sun Nov 03 09:35:10 UTC 2024
    - Last Modified: Mon Jun 17 03:58:13 UTC 2024
    - 15K bytes
    - Viewed (0)
  8. tests/update_test.go

    1. if users[1].Name != "update_column_02_newname" || users[1].Age != 100 {
    2. t.Errorf("user 2 should be updated with update column")
    3. }
    4. AssertEqual(t, lastUpdatedAt.UnixNano(), users[1].UpdatedAt.UnixNano())
    5.  
    6. // user2 should not be updated
    7. var user1, user2 User
    8. DB.First(&user1, users[0].ID)
    9. DB.First(&user2, users[1].ID)
    10. CheckUser(t, user1, *users[0])
    11. CheckUser(t, user2, *users[1])
    Registered: Sun Nov 03 09:35:10 UTC 2024
    - Last Modified: Mon Dec 04 03:50:58 UTC 2023
    - 30.3K bytes
    - Viewed (0)
  9. tests/scan_test.go

    1. }
    2.  
    3. DB.Table("users").Select("id, name, age").Where("id = ?", user2.ID).Scan(&res)
    4. if res.ID != user2.ID || res.Name != user2.Name || res.Age != int(user2.Age) {
    5. t.Fatalf("Scan into struct should work, got %#v, should %#v", res, user2)
    6. }
    7.  
    8. DB.Model(&User{Model: gorm.Model{ID: user3.ID}}).Select("id, name, age").Scan(&res)
    9. if res.ID != user3.ID || res.Name != user3.Name || res.Age != int(user3.Age) {
    Registered: Sun Nov 03 09:35:10 UTC 2024
    - Last Modified: Wed Jun 12 10:57:36 UTC 2024
    - 10.9K bytes
    - Viewed (0)
  10. tests/count_test.go

    1. func TestCount(t *testing.T) {
    2. var (
    3. user1 = *GetUser("count-1", Config{})
    4. user2 = *GetUser("count-2", Config{})
    5. user3 = *GetUser("count-3", Config{})
    6. users []User
    7. count, count1, count2 int64
    8. )
    9.  
    10. DB.Save(&user1).Save(&user2).Save(&user3)
    11.  
    12. if err := DB.Where("name = ?", user1.Name).Or("name = ?", user3.Name).Find(&users).Count(&count).Error; err != nil {
    Registered: Sun Nov 03 09:35:10 UTC 2024
    - Last Modified: Mon Oct 30 09:15:49 UTC 2023
    - 6.9K bytes
    - Viewed (0)
Back to top