Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity with custom ID through edge-schema doesn't resolve #4016

Open
2 tasks done
juliusmh opened this issue Apr 14, 2024 · 0 comments
Open
2 tasks done

Entity with custom ID through edge-schema doesn't resolve #4016

juliusmh opened this issue Apr 14, 2024 · 0 comments

Comments

@juliusmh
Copy link

juliusmh commented Apr 14, 2024

  • 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 馃槸

Running go generate is not possible.

$ go generate ./ent
entc/gen: resolving edges: missing edge-field Similarity.product_id for edge schema used by Product.alternatives in Through("similarities", Similarity.Type)
exit status 1
ent/generate.go:3: running "go": exit status 1

Expected Behavior 馃

The code should generate successfully.

Steps to Reproduce 馃暪

I copied the "friendships" example in Edge Schema
part of the documentation. I added a "custom" id to the Product entity.

func (Product) Fields() []ent.Field {
	return []ent.Field{
		field.UUID("id", uuid.UUID{}).Default(uuid.New),
	}
}

func (Product) Edges() []ent.Edge {
	return []ent.Edge{
		edge.To("alternatives", Product.Product).Through("similarities", Similarity.Type),
	}
}d
func (Similarity) Fields() []ent.Field {
	return []ent.Field{
		field.UUID("a_id", uuid.UUID{}),
		field.UUID("b_id", uuid.UUID{}),
	}
}

func (Similarity) Edges() []ent.Edge {
	return []ent.Edge{
		edge.To("a", Product.Type).
			Required().
			Unique().
			Field("a_id"),
		edge.To("b", Product.Type).
			Required().
			Unique().
			Field("b_id"),
	}
}

Your Environment 馃寧

Tech Version
Go 1.22.2
Ent 0.12.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant