Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 34 for Model (0.14 sec)

  1. tests/hooks_test.go

    		t.Fatalf("Failed to query product, got error: %v", err)
    	}
    
    	DB.Model(&result3).Update("Price", 800)
    	var result4 Product2
    	DB.First(&result4, "name = ?", "Nice2")
    
    	if result4.Price != 600 {
    		t.Errorf("Admin product's price should not be changed, expects: %v, got %v", 600, result4.Price)
    	}
    }
    
    type Product3 struct {
    	gorm.Model
    	Name  string
    	Code  string
    	Price int64
    	Owner string
    }
    
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Sat Feb 18 01:20:29 GMT 2023
    - 15.9K bytes
    - Viewed (0)
  2. chainable_api.go

    	"gorm.io/gorm/clause"
    	"gorm.io/gorm/utils"
    )
    
    // Model specify the model you would like to run db operations
    //
    //	// update all users's name to `hello`
    //	db.Model(&User{}).Update("name", "hello")
    //	// if user's primary key is non-blank, will use it as condition, then will only update that user's name to `hello`
    //	db.Model(&user).Update("name", "hello")
    func (db *DB) Model(value interface{}) (tx *DB) {
    	tx = db.getInstance()
    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)
  3. tests/associations_has_many_test.go

    	DB.Find(&user2, "id = ?", user.ID)
    	DB.Model(&user2).Association("Pets").Find(&user2.Pets)
    	CheckUser(t, user2, user)
    
    	var pets []Pet
    	DB.Model(&user).Where("name = ?", user.Pets[0].Name).Association("Pets").Find(&pets)
    
    	if len(pets) != 1 {
    		t.Fatalf("should only find one pets, but got %v", len(pets))
    	}
    
    	CheckPet(t, pets[0], *user.Pets[0])
    
    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. schema/relationship_test.go

    	} else {
    		for _, rel := range relations {
    			checkSchemaRelation(t, s, rel)
    		}
    	}
    }
    
    func TestBelongsToOverrideForeignKey(t *testing.T) {
    	type Profile struct {
    		gorm.Model
    		Name string
    	}
    
    	type User struct {
    		gorm.Model
    		Profile      Profile `gorm:"ForeignKey:ProfileRefer"`
    		ProfileRefer int
    	}
    
    	checkStructRelation(t, &User{}, Relation{
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Mon Apr 15 03:20:20 GMT 2024
    - 25.5K bytes
    - Viewed (0)
  5. tests/joins_test.go

    	if db5.Error != nil {
    		t.Errorf("Should not raise error for join where identical fields in different tables. Error: %s", db5.Error.Error())
    	}
    
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Wed Apr 26 14:19:32 GMT 2023
    - 13.5K bytes
    - Viewed (1)
  6. tests/table_test.go

    		}
    	}
    
    	r = dryDB.Table("(?) as u", DB.Model(&User{}).Select("name")).Find(&User{}).Statement
    	if !regexp.MustCompile("SELECT \\* FROM \\(SELECT .name. FROM .users. WHERE .users.\\..deleted_at. IS NULL\\) as u WHERE .u.\\..deleted_at. IS NULL").MatchString(r.Statement.SQL.String()) {
    		t.Errorf("Table with escape character, got %v", r.Statement.SQL.String())
    	}
    
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Sat Mar 09 09:31:28 GMT 2024
    - 10.6K bytes
    - Viewed (0)
  7. cmd/iam-etcd-store.go

    	//  a large number of policies
    	r, err := ies.client.Get(ctx, iamConfigPoliciesPrefix, etcd.WithPrefix())
    	if err != nil {
    		return err
    	}
    
    	// Parse all values to construct the policies data model.
    	for _, kvs := range r.Kvs {
    		if err = ies.getPolicyDocKV(ctx, kvs, m); err != nil && !errors.Is(err, errNoSuchPolicy) {
    			return err
    		}
    	}
    	return nil
    }
    
    Go
    - Registered: Sun May 05 19:28:20 GMT 2024
    - Last Modified: Thu Apr 04 12:04:40 GMT 2024
    - 13.6K bytes
    - Viewed (0)
  8. finisher_api.go

    	tx.Logger = currentLogger
    	return
    }
    
    // Pluck queries a single column from a model, returning in the slice dest. E.g.:
    //
    //	var ages []int64
    //	db.Model(&users).Pluck("age", &ages)
    func (db *DB) Pluck(column string, dest interface{}) (tx *DB) {
    	tx = db.getInstance()
    	if tx.Statement.Model != nil {
    		if tx.Statement.Parse(tx.Statement.Model) == nil {
    			if f := tx.Statement.Schema.LookUpField(column); f != nil {
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Fri Jan 12 08:42:21 GMT 2024
    - 22.7K bytes
    - Viewed (0)
  9. tests/create_test.go

    				t.Fatalf("errors happened when query: %v", err)
    			} else {
    				CheckUser(t, newUser, user)
    			}
    		}
    	}
    }
    
    func TestCreateFromMap(t *testing.T) {
    	if err := DB.Model(&User{}).Create(map[string]interface{}{"Name": "create_from_map", "Age": 18}).Error; err != nil {
    		t.Fatalf("failed to create data from map, got error: %v", err)
    	}
    
    	var result User
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Tue Mar 19 03:50:28 GMT 2024
    - 26.4K bytes
    - Viewed (0)
  10. migrator/migrator.go

    //
    //	// CREATE VIEW `user_view` AS SELECT * FROM `users` WHERE age > 20
    //	q := DB.Model(&User{}).Where("age > ?", 20)
    //	DB.Debug().Migrator().CreateView("user_view", gorm.ViewOption{Query: q})
    //
    //	// CREATE OR REPLACE VIEW `users_view` AS SELECT * FROM `users` WITH CHECK OPTION
    //	q := DB.Model(&User{})
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Fri Apr 26 07:15:49 GMT 2024
    - 29K bytes
    - Viewed (0)
Back to top