nil dereference when using through tables with composite key and custom index · Issue #2575 · ent/ent · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the example schema below, on latest (unreleased) version using the features from #2560 when using a composite ID key and a custom index on a custom field there is a nil deferefence error.
The issue is present in the latest release.
I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
nil dereference panic is thrown
Expected Behavior 🤔
panic not to be thrown
Steps to Reproduce 🕹
Example schema. Tested on entgo.io/ent v0.10.2-0.20220528091257-0917701f9114
package schema
import (
"entgo.io/ent""entgo.io/ent/schema""entgo.io/ent/schema/edge""entgo.io/ent/schema/field""entgo.io/ent/schema/index""time"
)
// User holds the schema definition for the User entity.typeUserstruct {
ent.Schema
}
// Fields of the User.func (User) Fields() []ent.Field {
return []ent.Field{
field.String("name").
Default("Unknown"),
}
}
// Edges of the User.func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("friends", User.Type).
Through("friendships", Friendship.Type),
}
}
// Friendship holds the edge schema definition of the Friendship relationship.typeFriendshipstruct {
ent.Schema
}
func (Friendship) Annotations() []schema.Annotation {
return []schema.Annotation{
field.ID("user_id", "friend_id"),
}
}
// Fields of the Friendship.func (Friendship) Fields() []ent.Field {
return []ent.Field{
field.Time("created_at").
Default(time.Now),
field.Int("user_id"),
field.Int("friend_id"),
}
}
// Edges of the Friendship.func (Friendship) Edges() []ent.Edge {
return []ent.Edge{
edge.To("user", User.Type).
Required().
Unique().
Field("user_id"),
edge.To("friend", User.Type).
Required().
Unique().
Field("friend_id"),
}
}
func (Friendship) Indexes() []ent.Index {
return []ent.Index{
index.Fields("created_at"),
}
}
Using the example schema below, on latest (unreleased) version using the features from #2560 when using a composite ID key and a custom index on a custom field there is a nil deferefence error.
Current Behavior 😯
nil dereference panic is thrown
Expected Behavior 🤔
panic not to be thrown
Steps to Reproduce 🕹
Example schema. Tested on
entgo.io/ent v0.10.2-0.20220528091257-0917701f9114
Your Environment 🌎
The text was updated successfully, but these errors were encountered: