entc/gen: add feature-flag to set unique backref when their inverse is loaded (#3953)

This commit is contained in:
Ariel Mashraki
2024-02-24 22:57:17 +02:00
committed by GitHub
parent d4560fae62
commit 7284481be5
87 changed files with 463 additions and 579 deletions

View File

@@ -45,12 +45,10 @@ type CardEdges struct {
// OwnerOrErr returns the Owner value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e CardEdges) OwnerOrErr() (*User, error) {
if e.loadedTypes[0] {
if e.Owner == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: user.Label}
}
if e.Owner != nil {
return e.Owner, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: user.Label}
}
return nil, &NotLoadedError{edge: "owner"}
}

View File

@@ -43,12 +43,10 @@ type UserEdges struct {
// CardOrErr returns the Card value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e UserEdges) CardOrErr() (*Card, error) {
if e.loadedTypes[0] {
if e.Card == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: card.Label}
}
if e.Card != nil {
return e.Card, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: card.Label}
}
return nil, &NotLoadedError{edge: "card"}
}