Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 13 for Unscoped (0.16 sec)

  1. chainable_api.go

    	return
    }
    
    // Unscoped disables the global scope of soft deletion in a query.
    // By default, GORM uses soft deletion, marking records as "deleted"
    // by setting a timestamp on a specific field (e.g., `deleted_at`).
    // Unscoped allows queries to include records marked as deleted,
    // overriding the soft deletion behavior.
    // Example:
    //    var users []User
    //    db.Unscoped().Find(&users)
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Wed Apr 17 03:38:55 GMT 2024
    - 14.3K bytes
    - Viewed (1)
  2. tests/helper_test.go

    }
    
    func isMysql() bool {
    	return os.Getenv("GORM_DIALECT") == "mysql"
    }
    
    func isSqlite() bool {
    	return os.Getenv("GORM_DIALECT") == "sqlite"
    }
    
    func db(unscoped bool) *gorm.DB {
    	if unscoped {
    		return DB.Unscoped()
    	} else {
    		return DB
    	}
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Tue Mar 19 03:50:28 GMT 2024
    - 8K bytes
    - Viewed (0)
  3. tests/associations_has_many_test.go

    	// test delete
    	if err := tx.Model(&item).Association("Contents").Unscoped().Delete(&contents[0]); err != nil {
    		t.Errorf("failed to delete Contents, got error: %v", err)
    	}
    	if count := tx.Model(&item).Association("Contents").Count(); count != 2 {
    		t.Errorf("expected %d contents, got %d", 2, count)
    	}
    
    	// test clear
    	if err := tx.Model(&item).Association("Contents").Unscoped().Clear(); err != nil {
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Fri Dec 15 08:36:08 GMT 2023
    - 15.6K bytes
    - Viewed (0)
  4. tests/sql_builder_test.go

    		t.Fatalf("invalid sql generated, got %v", sql)
    	}
    
    	sql = dryRunDB.Where("a = ? or b = ?", "a", "b").Unscoped().Find(&User{}).Statement.SQL.String()
    	if !regexp.MustCompile(`WHERE a = .+ or b = .+$`).MatchString(sql) {
    		t.Fatalf("invalid sql generated, got %v", sql)
    	}
    
    	sql = dryRunDB.Or("a = ? or b = ?", "a", "b").Unscoped().Find(&User{}).Statement.SQL.String()
    	if !regexp.MustCompile(`WHERE a = .+ or b = .+$`).MatchString(sql) {
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Fri Jan 12 08:42:21 GMT 2024
    - 16.7K bytes
    - Viewed (0)
  5. callbacks/create.go

    	supportReturning := utils.Contains(config.CreateClauses, "RETURNING")
    
    	return func(db *gorm.DB) {
    		if db.Error != nil {
    			return
    		}
    
    		if db.Statement.Schema != nil {
    			if !db.Statement.Unscoped {
    				for _, c := range db.Statement.Schema.CreateClauses {
    					db.Statement.AddClause(c)
    				}
    			}
    
    			if supportReturning && len(db.Statement.Schema.FieldsWithDefaultDBValue) > 0 {
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Mon Apr 08 03:29:55 GMT 2024
    - 12.5K bytes
    - Viewed (0)
  6. tests/delete_test.go

    	if err := DB.Table("deleted_users").Unscoped().First(&result3, user.ID).Error; err != nil {
    		t.Fatalf("failed to find record, got error %v", err)
    	}
    
    	if err := DB.Table("deleted_users").Unscoped().Delete(&result).Error; err != nil {
    		t.Errorf("failed to delete user with unscoped, got error %v", err)
    	}
    
    	var result4 UserWithDelete
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Tue Oct 10 07:03:34 GMT 2023
    - 9.4K bytes
    - Viewed (0)
  7. callbacks/preload.go

    				}
    			} else {
    				tx := db.Table("").Session(&gorm.Session{Context: db.Statement.Context, SkipHooks: db.Statement.SkipHooks})
    				tx.Statement.ReflectValue = db.Statement.ReflectValue
    				tx.Statement.Unscoped = db.Statement.Unscoped
    				if err := preload(tx, rel, append(preloads[name], associationsConds...), preloadMap[name]); err != nil {
    					return err
    				}
    			}
    		} else {
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Thu Apr 25 12:21:03 GMT 2024
    - 11.6K bytes
    - Viewed (0)
  8. tests/preload_test.go

    	if len(user4.Pets) != 0 {
    		t.Fatalf("User.Pet[0] was deleted and should not exist.")
    	}
    
    	var user5 User
    	DB.Unscoped().Preload(clause.Associations+"."+clause.Associations).Find(&user5, "id = ?", user.ID)
    	CheckUserUnscoped(t, user5, user)
    
    	var user6 *User
    	DB.Unscoped().Preload("Pets.Toy").Find(&user6, "id = ?", user.ID)
    	CheckUserUnscoped(t, *user6, user)
    }
    
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Thu Apr 25 12:21:03 GMT 2024
    - 14.9K bytes
    - Viewed (0)
  9. statement.go

    }
    
    func (stmt *Statement) clone() *Statement {
    	newStmt := &Statement{
    		TableExpr:            stmt.TableExpr,
    		Table:                stmt.Table,
    		Model:                stmt.Model,
    		Unscoped:             stmt.Unscoped,
    		Dest:                 stmt.Dest,
    		ReflectValue:         stmt.ReflectValue,
    		Clauses:              map[string]clause.Clause{},
    		Distinct:             stmt.Distinct,
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Fri Jan 12 08:42:21 GMT 2024
    - 19.8K bytes
    - Viewed (0)
  10. tests/associations_belongs_to_test.go

    			Logo: "logo",
    		},
    	}
    	if err := tx.Create(&item).Error; err != nil {
    		t.Fatalf("failed to create items, got error: %v", err)
    	}
    
    	// test replace
    	if err := tx.Model(&item).Association("ItemParent").Unscoped().Replace(&ItemParent{
    		Logo: "updated logo",
    	}); err != nil {
    		t.Errorf("failed to replace item parent, got error: %v", err)
    	}
    
    	var parents []ItemParent
    	if err := tx.Find(&parents).Error; err != nil {
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Mon Oct 30 09:15:49 GMT 2023
    - 9.3K bytes
    - Viewed (0)
Back to top