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.
41 lines
780 B
41 lines
780 B
4 years ago
|
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(),
|
||
|
}
|
||
|
}
|