mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
130 lines
3.7 KiB
Go
130 lines
3.7 KiB
Go
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
|
// This source code is licensed under the Apache 2.0 license found
|
|
// in the LICENSE file in the root directory of this source tree.
|
|
|
|
// Code generated by entc, DO NOT EDIT.
|
|
|
|
package entv2
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/facebookincubator/ent/dialect/sql"
|
|
"github.com/facebookincubator/ent/entc/integration/migrate/entv2/pet"
|
|
"github.com/facebookincubator/ent/entc/integration/migrate/entv2/user"
|
|
)
|
|
|
|
// Pet is the model entity for the Pet schema.
|
|
type Pet struct {
|
|
config
|
|
// ID of the ent.
|
|
ID int `json:"id,omitempty"`
|
|
// Edges holds the relations/edges for other nodes in the graph.
|
|
// The values are being populated by the PetQuery when eager-loading is set.
|
|
Edges PetEdges `json:"edges"`
|
|
owner_id *int
|
|
}
|
|
|
|
// PetEdges holds the relations/edges for other nodes in the graph.
|
|
type PetEdges struct {
|
|
// Owner holds the value of the owner edge.
|
|
Owner *User
|
|
// loadedTypes holds the information for reporting if a
|
|
// type was loaded (or requested) in eager-loading or not.
|
|
loadedTypes [1]bool
|
|
}
|
|
|
|
// 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 PetEdges) OwnerOrErr() (*User, error) {
|
|
if e.loadedTypes[0] {
|
|
if e.Owner == nil {
|
|
// The edge owner was loaded in eager-loading,
|
|
// but was not found.
|
|
return nil, &NotFoundError{label: user.Label}
|
|
}
|
|
return e.Owner, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "owner"}
|
|
}
|
|
|
|
// scanValues returns the types for scanning values from sql.Rows.
|
|
func (*Pet) scanValues() []interface{} {
|
|
return []interface{}{
|
|
&sql.NullInt64{}, // id
|
|
}
|
|
}
|
|
|
|
// fkValues returns the types for scanning foreign-keys values from sql.Rows.
|
|
func (*Pet) fkValues() []interface{} {
|
|
return []interface{}{
|
|
&sql.NullInt64{}, // owner_id
|
|
}
|
|
}
|
|
|
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
|
// to the Pet fields.
|
|
func (pe *Pet) assignValues(values ...interface{}) error {
|
|
if m, n := len(values), len(pet.Columns); m < n {
|
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
|
}
|
|
value, ok := values[0].(*sql.NullInt64)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field id", value)
|
|
}
|
|
pe.ID = int(value.Int64)
|
|
values = values[1:]
|
|
values = values[0:]
|
|
if len(values) == len(pet.ForeignKeys) {
|
|
if value, ok := values[0].(*sql.NullInt64); !ok {
|
|
return fmt.Errorf("unexpected type %T for edge-field owner_id", value)
|
|
} else if value.Valid {
|
|
pe.owner_id = new(int)
|
|
*pe.owner_id = int(value.Int64)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// QueryOwner queries the owner edge of the Pet.
|
|
func (pe *Pet) QueryOwner() *UserQuery {
|
|
return (&PetClient{config: pe.config}).QueryOwner(pe)
|
|
}
|
|
|
|
// Update returns a builder for updating this Pet.
|
|
// Note that, you need to call Pet.Unwrap() before calling this method, if this Pet
|
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
|
func (pe *Pet) Update() *PetUpdateOne {
|
|
return (&PetClient{config: pe.config}).UpdateOne(pe)
|
|
}
|
|
|
|
// Unwrap unwraps the entity that was returned from a transaction after it was closed,
|
|
// so that all next queries will be executed through the driver which created the transaction.
|
|
func (pe *Pet) Unwrap() *Pet {
|
|
tx, ok := pe.config.driver.(*txDriver)
|
|
if !ok {
|
|
panic("entv2: Pet is not a transactional entity")
|
|
}
|
|
pe.config.driver = tx.drv
|
|
return pe
|
|
}
|
|
|
|
// String implements the fmt.Stringer.
|
|
func (pe *Pet) String() string {
|
|
var builder strings.Builder
|
|
builder.WriteString("Pet(")
|
|
builder.WriteString(fmt.Sprintf("id=%v", pe.ID))
|
|
builder.WriteByte(')')
|
|
return builder.String()
|
|
}
|
|
|
|
// Pets is a parsable slice of Pet.
|
|
type Pets []*Pet
|
|
|
|
func (pe Pets) config(cfg config) {
|
|
for _i := range pe {
|
|
pe[_i].config = cfg
|
|
}
|
|
}
|