Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 58 for Associations (0.24 sec)

  1. callbacks/associations.go

    		tx = tx.Omit(clause.Associations)
    	}
    
    	if len(omits) > 0 {
    		tx = tx.Omit(omits...)
    	}
    
    	return db.AddError(tx.Create(values).Error)
    }
    
    // check association values has been saved
    // if values kind is Struct, check it has been saved
    // if values kind is Slice/Array, check all items have been saved
    var visitMapStoreKey = "gorm:saved_association_map"
    
    Go
    - Registered: Sun Apr 21 09:35:09 GMT 2024
    - Last Modified: Tue Apr 11 03:06:13 GMT 2023
    - 14.3K 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)
    	AssertEqual(t, err, gorm.ErrPrimaryKeyRequired)
    Go
    - Registered: Sun Apr 21 09:35:09 GMT 2024
    - Last Modified: Wed Feb 08 08:29:09 GMT 2023
    - 10.9K bytes
    - Viewed (0)
  3. tests/associations_many2many_test.go

    	// Clear
    	if err := DB.Model(&user2).Association("Languages").Clear(); err != nil {
    		t.Errorf("Error happened when clear Languages, got %v", err)
    	}
    
    	AssertAssociationCount(t, user2, "Languages", 0, "after clear")
    }
    
    func TestMany2ManyOmitAssociations(t *testing.T) {
    	tidbSkip(t, "not support the foreign key feature")
    
    	user := *GetUser("many2many_omit_associations", Config{Languages: 2})
    
    Go
    - Registered: Sun Apr 21 09:35:09 GMT 2024
    - Last Modified: Sat Jun 10 13:05:19 GMT 2023
    - 13.2K bytes
    - Viewed (0)
  4. tests/associations_belongs_to_test.go

    	// Clear
    	DB.Model(&users).Association("Company").Clear()
    	AssertAssociationCount(t, users, "Company", 0, "After Clear")
    
    	DB.Model(&users).Association("Manager").Clear()
    	AssertAssociationCount(t, users, "Manager", 0, "After Clear")
    
    	// shared company
    	company := Company{Name: "shared"}
    	if err := DB.Model(&users[0]).Association("Company").Append(&company); err != nil {
    Go
    - Registered: Sun Apr 21 09:35:09 GMT 2024
    - Last Modified: Mon Oct 30 09:15:49 GMT 2023
    - 9.3K bytes
    - Viewed (0)
  5. 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 Apr 21 09:35:09 GMT 2024
    - Last Modified: Fri Dec 15 08:36:08 GMT 2023
    - 15.6K bytes
    - Viewed (0)
  6. tests/associations_has_one_test.go

    	// 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 {
    		t.Fatalf("Error happened when append account, got %v", err)
    Go
    - Registered: Sun Apr 21 09:35:09 GMT 2024
    - Last Modified: Thu Jan 06 07:02:53 GMT 2022
    - 6.8K bytes
    - Viewed (0)
  7. tests/delete_test.go

    	users := []User{
    		*GetUser("delete_slice_with_associations1", Config{Account: true, Pets: 4, Toys: 1, Company: true, Manager: true, Team: 1, Languages: 1, Friends: 4}),
    		*GetUser("delete_slice_with_associations2", Config{Account: true, Pets: 3, Toys: 2, Company: true, Manager: true, Team: 2, Languages: 2, Friends: 3}),
    Go
    - Registered: Sun Apr 21 09:35:09 GMT 2024
    - Last Modified: Tue Oct 10 07:03:34 GMT 2023
    - 9.4K bytes
    - Viewed (0)
  8. tests/preload_test.go

    				},
    				AddressID:     org.AddressID,
    				Address:       nil,
    				NestedAddress: org.NestedAddress,
    			},
    		}, {
    			name: "associations",
    			preloads: map[string][]interface{}{
    				clause.Associations: {},
    				// clause.Associations won’t preload nested associations
    				"Address.Country": {},
    			},
    			expect: org,
    		},
    	}
    
    	for _, test := range tests {
    		t.Run(test.name, func(t *testing.T) {
    Go
    - Registered: Sun Apr 21 09:35:09 GMT 2024
    - Last Modified: Mon Apr 15 03:20:20 GMT 2024
    - 13.4K bytes
    - Viewed (0)
  9. clause/clause.go

    			builder.WriteByte(' ')
    			c.AfterExpression.Build(builder)
    		}
    	}
    }
    
    const (
    	PrimaryKey   string = "~~~py~~~" // primary key
    	CurrentTable string = "~~~ct~~~" // current table
    	Associations string = "~~~as~~~" // associations
    )
    
    var (
    	currentTable  = Table{Name: CurrentTable}
    	PrimaryColumn = Column{Table: CurrentTable, Name: PrimaryKey}
    )
    
    // Column quote with name
    type Column struct {
    	Table string
    Go
    - Registered: Sun Apr 21 09:35:09 GMT 2024
    - Last Modified: Thu Feb 02 09:15:08 GMT 2023
    - 1.7K bytes
    - Viewed (0)
  10. callbacks/callbacks.go

    	createCallback.Register("gorm:before_create", BeforeCreate)
    	createCallback.Register("gorm:save_before_associations", SaveBeforeAssociations(true))
    	createCallback.Register("gorm:create", Create(config))
    	createCallback.Register("gorm:save_after_associations", SaveAfterAssociations(true))
    	createCallback.Register("gorm:after_create", AfterCreate)
    Go
    - Registered: Sun Apr 21 09:35:09 GMT 2024
    - Last Modified: Wed Oct 27 23:56:55 GMT 2021
    - 3.3K bytes
    - Viewed (0)
Back to top