Skip to content

entproto doesn't respect immutble edges. #3843

Open
ent/contrib
#560
@lesomnus

Description

@lesomnus
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions