Search Options

Results per page
Sort
Preferred Languages
Advance

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

  1. tests/associations_many2many_test.go

    	// Find
    	var user2 User
    	DB.Find(&user2, "id = ?", user.ID)
    	DB.Model(&user2).Association("Languages").Find(&user2.Languages)
    
    	CheckUser(t, user2, user)
    
    	// Count
    	AssertAssociationCount(t, user, "Languages", 2, "")
    
    	// Append
    	language := Language{Code: "language-many2many-append", Name: "language-many2many-append"}
    	DB.Create(&language)
    
    	if err := DB.Model(&user2).Association("Languages").Append(&language); err != nil {
    Go
    - Registered: Sun Apr 28 09:35:09 GMT 2024
    - Last Modified: Sat Jun 10 13:05:19 GMT 2023
    - 13.2K bytes
    - Viewed (0)
  2. tests/associations_test.go

    	var emptyUser User
    	var err error
    	// belongs to
    	err = DB.Model(&emptyUser).Association("Company").Delete(&user1.Company)
    	AssertEqual(t, err, gorm.ErrPrimaryKeyRequired)
    	// has many
    	err = DB.Model(&emptyUser).Association("Pets").Delete(&user1.Pets)
    	AssertEqual(t, err, gorm.ErrPrimaryKeyRequired)
    	// has one
    	err = DB.Model(&emptyUser).Association("Account").Delete(&user1.Account)
    Go
    - Registered: Sun Apr 28 09:35:09 GMT 2024
    - Last Modified: Wed Feb 08 08:29:09 GMT 2023
    - 10.9K bytes
    - Viewed (0)
  3. tests/update_test.go

    	}
    
    	user3.Name = "save3_"
    	if err := DB.Model(User{Model: user3.Model}).Save(&user3).Error; err != nil {
    		t.Fatalf("failed to save user, got %v", err)
    	}
    
    	var result2 User
    	if err := DB.First(&result2, "name = ?", "save3_").Error; err != nil || result2.ID != user3.ID {
    		t.Fatalf("failed to find updated user, got %v", err)
    	}
    
    	if err := DB.Model(User{Model: user3.Model}).Save(&struct {
    		gorm.Model
    Go
    - Registered: Sun Apr 28 09:35:09 GMT 2024
    - Last Modified: Mon Dec 04 03:50:58 GMT 2023
    - 30.3K bytes
    - Viewed (0)
  4. 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 Apr 28 09:35:09 GMT 2024
    - Last Modified: Sat Feb 18 01:20:29 GMT 2023
    - 15.9K bytes
    - Viewed (0)
  5. association.go

    					association.Error = associationDB.Model(nil).Where(clause.IN{Column: column, Values: values}).Delete(reflect.New(rel.FieldSchema.ModelType).Interface()).Error
    				}
    			}
    		case schema.HasOne, schema.HasMany:
    			model := reflect.New(rel.FieldSchema.ModelType).Interface()
    			tx := association.DB.Model(model)
    
    Go
    - Registered: Sun Apr 28 09:35:09 GMT 2024
    - Last Modified: Thu May 04 11:30:45 GMT 2023
    - 21.2K bytes
    - Viewed (0)
  6. tests/multi_primary_keys_test.go

    	DB.Model(&blog).Association("Tags").Delete(tag5)
    	var tags3 []Tag
    	DB.Model(&blog).Association("Tags").Find(&tags3)
    	if !compareTags(tags3, []string{"tag6"}) {
    		t.Fatalf("Should find 1 tags after Delete")
    	}
    
    	if DB.Model(&blog).Association("Tags").Count() != 1 {
    		t.Fatalf("Blog should has three tags after Delete")
    	}
    
    	DB.Model(&blog).Association("Tags").Delete(tag3)
    	var tags4 []Tag
    Go
    - Registered: Sun Apr 28 09:35:09 GMT 2024
    - Last Modified: Thu Jan 06 07:02:53 GMT 2022
    - 12.8K bytes
    - Viewed (0)
  7. tests/sql_builder_test.go

    	dryRunDB := DB.Session(&gorm.Session{DryRun: true})
    
    	stmt := dryRunDB.Model(&user).Where("id = ?", 1).Updates(map[string]interface{}{"age": ageInt(8)}).Statement
    	sql := DB.Dialector.Explain(stmt.SQL.String(), stmt.Vars...)
    	if !regexp.MustCompile(`.*age.*=8,`).MatchString(sql) {
    		t.Errorf("Failed to generate sql, got %v", sql)
    	}
    
    Go
    - Registered: Sun Apr 28 09:35:09 GMT 2024
    - Last Modified: Fri Jan 12 08:42:21 GMT 2024
    - 16.7K bytes
    - Viewed (0)
  8. 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 Apr 28 09:35:09 GMT 2024
    - Last Modified: Wed Apr 17 03:38:55 GMT 2024
    - 14.3K bytes
    - Viewed (1)
  9. tests/scanner_valuer_test.go

    	if err := DB.Create(&data).Error; err != nil {
    		t.Errorf("Should got no error when creating data, but got %v", err)
    	}
    
    	if err := DB.Model(&data).Update("password", EncryptedData("xnewpass")).Error; err == nil {
    		t.Errorf("Should failed to update data with invalid data")
    	}
    
    	if err := DB.Model(&data).Update("password", EncryptedData("newpass")).Error; err != nil {
    		t.Errorf("Should got no error update data with valid data, but got %v", err)
    Go
    - Registered: Sun Apr 28 09:35:09 GMT 2024
    - Last Modified: Wed Jun 07 07:02:07 GMT 2023
    - 10.6K bytes
    - Viewed (0)
  10. schema/schema_test.go

    		{Name: "ID", DBName: "id", BindNames: []string{"Model", "ID"}, DataType: schema.Uint, PrimaryKey: true, Tag: `gorm:"primarykey"`, TagSettings: map[string]string{"PRIMARYKEY": "PRIMARYKEY"}, Size: 64, HasDefaultValue: true, AutoIncrement: true},
    		{Name: "CreatedAt", DBName: "created_at", BindNames: []string{"Model", "CreatedAt"}, DataType: schema.Time},
    		{Name: "UpdatedAt", DBName: "updated_at", BindNames: []string{"Model", "UpdatedAt"}, DataType: schema.Time},
    Go
    - Registered: Sun Apr 28 09:35:09 GMT 2024
    - Last Modified: Fri Dec 15 08:31:23 GMT 2023
    - 12.9K bytes
    - Viewed (0)
Back to top