2020-01-31 07:22:37 +03:00
|
|
|
package schema
|
2020-01-29 14:22:44 +03:00
|
|
|
|
|
|
|
// RelationshipType relationship type
|
|
|
|
type RelationshipType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
HasOneRel RelationshipType = "has_one" // HasOneRel has one relationship
|
|
|
|
HasManyRel RelationshipType = "has_many" // HasManyRel has many relationship
|
|
|
|
BelongsToRel RelationshipType = "belongs_to" // BelongsToRel belongs to relationship
|
|
|
|
Many2ManyRel RelationshipType = "many_to_many" // Many2ManyRel many to many relationship
|
|
|
|
)
|
|
|
|
|
|
|
|
type Relationships struct {
|
|
|
|
HasOne map[string]*Relationship
|
|
|
|
BelongsTo map[string]*Relationship
|
|
|
|
HasMany map[string]*Relationship
|
|
|
|
Many2Many map[string]*Relationship
|
|
|
|
}
|
|
|
|
|
|
|
|
type Relationship struct {
|
|
|
|
Type RelationshipType
|
|
|
|
ForeignKeys []*RelationField // self
|
|
|
|
AssociationForeignKeys []*RelationField // association
|
|
|
|
JoinTable *JoinTable
|
|
|
|
}
|
|
|
|
|
|
|
|
type RelationField struct {
|
|
|
|
*Field
|
|
|
|
PolymorphicField *Field
|
|
|
|
PolymorphicValue string
|
|
|
|
}
|
|
|
|
|
|
|
|
type JoinTable struct {
|
|
|
|
Table string
|
|
|
|
ForeignKeys []*RelationField
|
|
|
|
AssociationForeignKeys []*RelationField
|
|
|
|
}
|
2020-01-31 07:22:37 +03:00
|
|
|
|
|
|
|
func (schema *Schema) buildToOneRel(field *Field) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (schema *Schema) buildToManyRel(field *Field) {
|
|
|
|
}
|