package schema import ( "entgo.io/ent" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" "time" ) // Product holds the schema definition for the Product entity. type Product struct { ent.Schema } // Fields of the Product. func (Product) Fields() []ent.Field { return []ent.Field{ field.String("name").Default("unknown"), field.Text("summary").Optional().Nillable(), field.Text("description").Optional().Nillable(), field.Float("price").Default(0).Positive(), field.Float("original_price").Default(0).Positive(), field.Int("quantity").Default(0).Positive(), field.Bool("status").Default(true), field.Int("product_category_id").Optional().Nillable(), field.Int("business_id").Optional().Nillable(), field.Int("user_id").Optional().Nillable(), field.Time("created_at").Default(time.Now()), field.Time("updated_at").Default(time.Now()).UpdateDefault(time.Now), } } // Edges of the Product. func (Product) Edges() []ent.Edge { return []ent.Edge{ edge.From("product_categories", ProductCategory.Type).Ref("products").Unique().Field("product_category_id"), edge.From("businesses", Business.Type).Ref("products").Unique().Field("business_id"), edge.From("users", User.Type).Ref("products").Unique().Field("user_id"), } }