You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
780 B
40 lines
780 B
package schema
|
|
|
|
import (
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect"
|
|
"entgo.io/ent/schema/edge"
|
|
"entgo.io/ent/schema/field"
|
|
"time"
|
|
)
|
|
|
|
// Comment holds the schema definition for the Comment entity.
|
|
type Comment struct {
|
|
ent.Schema
|
|
}
|
|
|
|
// Fields of the Comment.
|
|
func (Comment) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.Int64("id"),
|
|
field.String("name"),
|
|
field.String("content"),
|
|
field.Time("created_at").
|
|
Default(time.Now).SchemaType(map[string]string{
|
|
dialect.MySQL: "datetime",
|
|
}),
|
|
field.Time("updated_at").
|
|
Default(time.Now).SchemaType(map[string]string{
|
|
dialect.MySQL: "datetime",
|
|
}),
|
|
}
|
|
}
|
|
|
|
// Edges of the Comment.
|
|
func (Comment) Edges() []ent.Edge {
|
|
return []ent.Edge{
|
|
edge.From("post", Article.Type).
|
|
Ref("comments").
|
|
Unique(),
|
|
}
|
|
}
|
|
|