Follow-up to #81.
Describe the bug
When WithReverseEdge is enabled, the generated EventHistory edge is inverted. It uses edge.To("event", Event.Type) which makes ent generate extra FK fields/constraints on the history table. The reverse edge should be defined using edge.From(...).Ref(...).Field("ref") to attach to the existing ref field.
To Reproduce
Minimal schema:
// EventHistory schema
func (EventHistory) Edges() []ent.Edge {
return []ent.Edge{
// Generated by extension (currently)
edge.To("event", Event.Type).Unique(),
}
}
// Event schema
func (Event) Edges() []ent.Edge {
return []ent.Edge{
edge.To("history", EventHistory.Type),
}
}
Generator setup:
enthistory.Generate(
// ...
enthistory.WithReverseEdge(),
)
entc.Generate(
// ...
enthistory.NewHistoryExtension(
enthistory.WithReverseEdgeExtension(),
),
)
Expected behavior
The generated EventHistory edge should be:
edge.From("event", Event.Type).
Ref("history").
Field("ref").
Unique().
Immutable()
This keeps the FK on event_history.ref and avoids ent generating unnecessary fields/constraints.
Screenshots
N/A
Additional context
This only happens when WithReverseEdge() and WithReverseEdgeExtension() are used together.
Follow-up to #81.
Describe the bug
When
WithReverseEdgeis enabled, the generatedEventHistoryedge is inverted. It usesedge.To("event", Event.Type)which makesentgenerate extra FK fields/constraints on the history table. The reverse edge should be defined usingedge.From(...).Ref(...).Field("ref")to attach to the existingreffield.To Reproduce
Minimal schema:
Generator setup:
Expected behavior
The generated
EventHistoryedge should be:This keeps the FK on
event_history.refand avoidsentgenerating unnecessary fields/constraints.Screenshots
N/A
Additional context
This only happens when
WithReverseEdge()andWithReverseEdgeExtension()are used together.