Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 6 of 6 for POLYMORPHIC (0.05 sec)

  1. schema/relationship.go

    //	  OwnerType string
    //	}
    func (schema *Schema) buildPolymorphicRelation(relation *Relationship, field *Field) {
    	polymorphic := field.TagSettings["POLYMORPHIC"]
    
    	relation.Polymorphic = &Polymorphic{
    		Value: schema.Table,
    	}
    
    	var (
    		typeName = polymorphic + "Type"
    		typeId   = polymorphic + "ID"
    	)
    
    	if value, ok := field.TagSettings["POLYMORPHICTYPE"]; ok {
    		typeName = strings.TrimSpace(value)
    	}
    Registered: Sun Dec 28 09:35:17 UTC 2025
    - Last Modified: Sun Nov 16 04:11:05 UTC 2025
    - 23.1K bytes
    - Viewed (1)
  2. schema/relationship_test.go

    						Schema:      "User",
    						FieldSchema: "Toy",
    						Polymorphic: Polymorphic{ID: "OwnerID", Type: "OwnerType", Value: "users"},
    						References: []Reference{
    							{ForeignKey: "OwnerType", ForeignSchema: "Toy", PrimaryValue: "users"},
    						},
    					},
    				},
    			},
    		})
    	})
    
    	t.Run("has one with custom polymorphic type and id", func(t *testing.T) {
    		type Toy struct {
    			ID    int
    Registered: Sun Dec 28 09:35:17 UTC 2025
    - Last Modified: Mon Aug 18 11:44:52 UTC 2025
    - 26.5K bytes
    - Viewed (0)
  3. schema/schema_helper_test.go

    			}
    
    			if r.Polymorphic != nil {
    				if r.Polymorphic.PolymorphicID.Name != relation.Polymorphic.ID {
    					t.Errorf("schema %v relation's polymorphic id field expects %v, but got %v", s, relation.Polymorphic.ID, r.Polymorphic.PolymorphicID.Name)
    				}
    
    				if r.Polymorphic.PolymorphicType.Name != relation.Polymorphic.Type {
    Registered: Sun Dec 28 09:35:17 UTC 2025
    - Last Modified: Thu Aug 28 02:57:17 UTC 2025
    - 7.5K bytes
    - Viewed (0)
  4. schema/schema_test.go

    			References: []Reference{{"ID", "User", "UserID", "Pet", "", true}},
    		},
    		{
    			Name: "Toys", Type: schema.HasMany, Schema: "User", FieldSchema: "Toy",
    			Polymorphic: Polymorphic{ID: "OwnerID", Type: "OwnerType", Value: "users"},
    			References:  []Reference{{"ID", "User", "OwnerID", "Toy", "", true}, {"", "", "OwnerType", "Toy", "users", false}},
    		},
    		{
    Registered: Sun Dec 28 09:35:17 UTC 2025
    - Last Modified: Thu Aug 28 02:57:17 UTC 2025
    - 13.3K bytes
    - Viewed (0)
  5. tests/association_generics_test.go

    		t.Fatalf("Set Update many2many clear failed: %v", err)
    	} else if rows != 0 {
    		t.Fatalf("expected 0 rows affected, got %d", rows)
    	}
    	AssertAssociationCount(t, user, "Languages", 0, "after clear")
    }
    
    // Polymorphic Tools create and unlink
    func TestClauseAssociationSetUpdatePolymorphicTools(t *testing.T) {
    	ctx := context.Background()
    	user := User{Name: "TestClauseAssociationSetUpdatePolymorphicTools", Age: 25}
    Registered: Sun Dec 28 09:35:17 UTC 2025
    - Last Modified: Fri Sep 12 05:42:26 UTC 2025
    - 37.9K bytes
    - Viewed (0)
  6. tests/associations_has_many_test.go

    	// Find
    	var toys []Toy
    	if DB.Model(&users).Association("Toys").Find(&toys); len(toys) != 6 {
    		t.Errorf("toys count should be %v, but got %v", 6, len(toys))
    	}
    
    	// Find Tools (polymorphic with custom type and id)
    	var tools []Tools
    	DB.Model(&users).Association("Tools").Find(&tools)
    
    	if len(tools) != 2 {
    		t.Errorf("tools count should be %v, but got %v", 2, len(tools))
    	}
    
    	// Append
    Registered: Sun Dec 28 09:35:17 UTC 2025
    - Last Modified: Fri Sep 12 04:33:27 UTC 2025
    - 16.3K bytes
    - Viewed (0)
Back to top