Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 81 for Model (0.2 sec)

  1. model.go

    package gorm
    
    import "time"
    
    // Model a basic GoLang struct which includes the following fields: ID, CreatedAt, UpdatedAt, DeletedAt
    // It may be embedded into your model or you may build your own model without it
    //
    //	type User struct {
    //	  gorm.Model
    //	}
    type Model struct {
    	ID        uint `gorm:"primarykey"`
    	CreatedAt time.Time
    	UpdatedAt time.Time
    	DeletedAt DeletedAt `gorm:"index"`
    Go
    - Registered: Sun Apr 28 09:35:09 GMT 2024
    - Last Modified: Sat Feb 18 01:06:43 GMT 2023
    - 396 bytes
    - Viewed (0)
  2. schema/model_test.go

    package schema_test
    
    import (
    	"database/sql"
    	"time"
    
    	"gorm.io/gorm"
    	"gorm.io/gorm/utils/tests"
    )
    
    type User struct {
    	*gorm.Model
    	Name      *string
    	Age       *uint
    	Birthday  *time.Time
    	Account   *tests.Account
    	Pets      []*tests.Pet
    	Toys      []*tests.Toy `gorm:"polymorphic:Owner"`
    	CompanyID *int
    	Company   *tests.Company
    	ManagerID *uint
    	Manager   *User
    Go
    - Registered: Sun Apr 28 09:35:09 GMT 2024
    - Last Modified: Thu Jan 06 07:02:53 GMT 2022
    - 1.1K bytes
    - Viewed (0)
  3. 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)
  4. tests/associations_has_one_test.go

    	CheckUser(t, user, user)
    
    	// Find
    	var user2 User
    	DB.Find(&user2, "id = ?", user.ID)
    	DB.Model(&user2).Association("Account").Find(&user2.Account)
    	CheckUser(t, user2, user)
    
    	// Count
    	AssertAssociationCount(t, user, "Account", 1, "")
    
    	// Append
    	account := Account{Number: "account-has-one-append"}
    
    	if err := DB.Model(&user2).Association("Account").Append(&account); err != nil {
    Go
    - Registered: Sun Apr 28 09:35:09 GMT 2024
    - Last Modified: Thu Jan 06 07:02:53 GMT 2022
    - 6.8K bytes
    - Viewed (0)
  5. 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)
  6. utils/tests/models.go

    	Active    bool
    }
    
    type Account struct {
    	gorm.Model
    	UserID sql.NullInt64
    	Number string
    }
    
    type Pet struct {
    	gorm.Model
    	UserID *uint
    	Name   string
    	Toy    Toy `gorm:"polymorphic:Owner;"`
    }
    
    type Toy struct {
    	gorm.Model
    	Name      string
    	OwnerID   string
    	OwnerType string
    }
    
    type Tools struct {
    	gorm.Model
    	Name     string
    	CustomID string
    	Type     string
    }
    
    Go
    - Registered: Sun Apr 28 09:35:09 GMT 2024
    - Last Modified: Fri Dec 15 08:36:08 GMT 2023
    - 2.1K bytes
    - Viewed (0)
  7. 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)
  8. 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)
  9. 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)
  10. tests/named_polymorphic_test.go

    	}
    
    	if DB.Model(&hamster2).Association("OtherToy").Count() != 1 {
    		t.Errorf("Hamster's toys count should be 1 after Append")
    	}
    
    	// Replace
    	DB.Model(&hamster).Association("PreferredToy").Replace(&Toy{
    		Name: "bike 3",
    	})
    
    	DB.Model(&hamster).Association("OtherToy").Replace(&Toy{
    		Name: "treadmill 3",
    	})
    
    	hamsterToy = Toy{}
    Go
    - Registered: Sun Apr 28 09:35:09 GMT 2024
    - Last Modified: Wed Jul 08 09:59:40 GMT 2020
    - 4.2K bytes
    - Viewed (0)
Back to top