package schema import ( "time" "entgo.io/ent" "entgo.io/ent/dialect/entsql" "entgo.io/ent/schema" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" "github.com/google/uuid" ) // ChampPersonnalise represente un champ dynamique associe a un objet. type ChampPersonnalise struct { ent.Schema } // Fields de l'entite ChampPersonnalise. func (ChampPersonnalise) Fields() []ent.Field { return []ent.Field{ field.UUID("id", uuid.UUID{}). Default(uuid.New). Comment("Identifiant unique du champ"), field.UUID("objet_id", uuid.UUID{}). Comment("Identifiant de l'objet"), field.String("nom_champ"). NotEmpty(). Comment("Nom du champ"), field.Enum("type_champ"). Values("string", "int", "bool", "date"). Default("string"). Comment("Type du champ"), field.String("valeur"). Optional(). Nillable(). Comment("Valeur stockee en texte"), field.String("unite"). Optional(). Nillable(). Comment("Unite (si applicable)"), field.Time("created_at"). Default(time.Now). Comment("Date de creation"), field.Time("updated_at"). Default(time.Now). UpdateDefault(time.Now). Comment("Date de derniere mise a jour"), } } // Annotations pour le nom de table. func (ChampPersonnalise) Annotations() []schema.Annotation { return []schema.Annotation{ entsql.Annotation{Table: "champ_personnalise"}, } } // Edges de l'entite ChampPersonnalise. func (ChampPersonnalise) Edges() []ent.Edge { return []ent.Edge{ edge.From("objet", Objet.Type). Ref("champs_personnalises"). Unique(). Field("objet_id"). Required(), } }