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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

entproto doesn't respect immutble edges. #3843

Open
2 tasks done
lesomnus opened this issue Nov 24, 2023 · 0 comments · May be fixed by ent/contrib#560
Open
2 tasks done

entproto doesn't respect immutble edges. #3843

lesomnus opened this issue Nov 24, 2023 · 0 comments · May be fixed by ent/contrib#560

Comments

@lesomnus
Copy link

  • 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 😯

Assume Person has immutable edge to Pet (e.g. Person is owner of Pet).
Code for PetService.Update is generated as follow:

	if pet.GetOwner() != nil {
		petOwner := int(pet.GetOwner().GetId())
		m.SetOwnerID(petOwner)  // <- SetOwnerID undefined since the edge is immutable.
	}

Expected Behavior 🤔

The code if pet.GetOwner() != nil { ... } should not be generated.

Steps to Reproduce 🕹

// Edges of the Person.
func (Person) Edges() []ent.Edge {
	return []ent.Edge{
		edge.To("pets", Pet.Type).
			Annotations(entproto.Field(2)),
	}
}

// Edges of the Pet.
func (Pet) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("owner", Person.Type).Ref("pets").Immutable().Unique().Required().
		Annotations(entproto.Field(2)),
	}
}

Your Environment 🌎

Tech Version
Go go1.21.4 linux/amd64
Ent v0.12.5
Database N/A
Driver N/A
entgo.io/contrib v0.4.6-0.20231111095018-6ed0397cd307
@lesomnus lesomnus changed the title entproto doesn't repect immutble edges. entproto doesn't respect immutble edges. Nov 24, 2023
@lesomnus lesomnus linked a pull request Nov 24, 2023 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant