35 lines
847 B
Go
35 lines
847 B
Go
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.String("description").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.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("productCategory", ProductCategory.Type).Ref("products"),
|
|
}
|
|
}
|