Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 12 for Pet (0.12 sec)

  1. tests/associations_has_many_test.go

    	CheckUser(t, user2, user)
    
    	AssertAssociationCount(t, user, "Pets", 3, "AfterAppend")
    
    	pets2 := []Pet{{Name: "pet-has-many-append-1-1"}, {Name: "pet-has-many-append-1-1"}}
    
    	if err := DB.Model(&user2).Association("Pets").Append(&pets2); err != nil {
    		t.Fatalf("Error happened when append pet, got %v", err)
    	}
    
    	for _, pet := range pets2 {
    		pet := pet
    		if pet.ID == 0 {
    			t.Fatalf("Pet's ID should be created")
    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)
  2. tests/joins_test.go

    	DB.Save(&user)
    
    	var user1 User
    	onQuery := DB.Where(&Pet{Name: "joins-on_pet_1"})
    
    	if err := DB.Joins("NamedPet", onQuery).Where("users.name = ?", user.Name).First(&user1).Error; err != nil {
    		t.Fatalf("Failed to load with joins on, got error: %v", err)
    	}
    
    	AssertEqual(t, user1.NamedPet.Name, "joins-on_pet_1")
    
    	onQuery2 := DB.Where(&Pet{Name: "joins-on_pet_2"})
    	var user2 User
    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)
  3. tests/preload_test.go

    	for idx, user := range users2[0:2] {
    		for _, pet := range user.Pets {
    			if pet.Toy.Name != "" {
    				t.Errorf("No toy should for user %v's pet %v but got %v", idx+1, pet.Name, pet.Toy.Name)
    			}
    		}
    	}
    
    	if len(users2[2].Pets) != 3 {
    		t.Errorf("Invalid pet toys found for user 3 got %v", len(users2[2].Pets))
    	} else {
    		sort.Slice(users2[2].Pets, func(i, j int) bool {
    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)
  4. tests/create_test.go

    	t.Run("Struct", func(t *testing.T) {
    		pet := Pet{
    			Name: "PolymorphicHasOne",
    			Toy:  Toy{Name: "Toy-PolymorphicHasOne"},
    		}
    
    		if err := DB.Create(&pet).Error; err != nil {
    			t.Fatalf("errors happened when create: %v", err)
    		}
    
    		CheckPet(t, pet, pet)
    
    		var pet2 Pet
    		DB.Preload("Toy").Find(&pet2, "id = ?", pet.ID)
    		CheckPet(t, pet2, pet)
    	})
    
    	t.Run("Slice", func(t *testing.T) {
    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)
  5. tests/table_test.go

    		t.Errorf("Table with escape character, got %v", r.Statement.SQL.String())
    	}
    
    	r = dryDB.Table("(?) as u, (?) as p", DB.Model(&User{}).Select("name"), DB.Model(&Pet{}).Select("name")).Find(&User{}).Statement
    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)
  6. schema/relationship.go

    			}
    			relationships.Relations[relation.Name] = relation
    		}
    	}
    }
    
    // User has many Toys, its `Polymorphic` is `Owner`, Pet has one Toy, its `Polymorphic` is `Owner`
    //
    //	type User struct {
    //	  Toys []Toy `gorm:"polymorphic:Owner;"`
    //	}
    //	type Pet struct {
    //	  Toy Toy `gorm:"polymorphic:Owner;"`
    //	}
    //	type Toy struct {
    //	  OwnerID   int
    //	  OwnerType string
    //	}
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Mon Apr 15 03:20:20 GMT 2024
    - 22.4K bytes
    - Viewed (0)
  7. schema/schema_test.go

    			References: []Reference{{"ID", "User", "UserID", "Account", "", true}},
    		},
    		{
    			Name: "Pets", Type: schema.HasMany, Schema: "User", FieldSchema: "Pet",
    			References: []Reference{{"ID", "User", "UserID", "Pet", "", true}},
    		},
    		{
    			Name: "Toys", Type: schema.HasMany, Schema: "User", FieldSchema: "Toy",
    			Polymorphic: Polymorphic{ID: "OwnerID", Type: "OwnerType", Value: "users"},
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Fri Dec 15 08:31:23 GMT 2023
    - 12.9K bytes
    - Viewed (0)
  8. tests/upsert_test.go

    	}
    
    	DB.Where(&User{Name: "find or create embedded struct"}).Assign(User{Age: 44, Account: Account{Number: "1231231231"}, Pets: []*Pet{{Name: "first_or_create_pet1"}, {Name: "first_or_create_pet2"}}}).FirstOrCreate(&user8)
    	if err := DB.Where("name = ?", "first_or_create_pet1").First(&Pet{}).Error; err != nil {
    		t.Errorf("has many association should be saved")
    	}
    
    Go
    - Registered: Sun May 05 09:35:13 GMT 2024
    - Last Modified: Mon Sep 05 07:39:19 GMT 2022
    - 11.4K bytes
    - Viewed (0)
  9. docs/en/docs/tutorial/sql-databases.md

    So, `orion_cat.owner.name` could be the name (from the `name` column in the `owners` table) of this pet's owner.
    
    It could have a value like `"Arquilian"`.
    
    And the ORM will do all the work to get the information from the corresponding table *owners* when you try to access it from your pet object.
    
    Plain Text
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Thu Apr 18 19:53:19 GMT 2024
    - 29.6K bytes
    - Viewed (0)
  10. docs/zh/docs/tutorial/sql-databases.md

    **FastAPI**可与任何数据库在任何样式的库中一起与 数据库进行通信。
    
    一种常见的模式是使用“ORM”:对象关系映射。
    
    ORM 具有在代码和数据库表(“*关系型”)中的**对象**之间转换(“*映射*”)的工具。
    
    使用 ORM,您通常会在 SQL 数据库中创建一个代表映射的类,该类的每个属性代表一个列,具有名称和类型。
    
    例如,一个类`Pet`可以表示一个 SQL 表`pets`。
    
    该类的每个*实例对象都代表数据库中的一行数据。*
    
    又例如,一个对象`orion_cat`(`Pet`的一个实例)可以有一个属性`orion_cat.type`, 对标数据库中的`type`列。并且该属性的值可以是其它,例如`"cat"`。
    
    这些 ORM 还具有在表或实体之间建立关系的工具(比如创建多表关系)。
    
    这样,您还可以拥有一个属性`orion_cat.owner`,它包含该宠物所有者的数据,这些数据取自另外一个表。
    
    Plain Text
    - Registered: Sun May 05 07:19:11 GMT 2024
    - Last Modified: Fri Mar 22 01:42:11 GMT 2024
    - 27K bytes
    - Viewed (0)
Back to top