2023-10-27 09:51:58 +00:00
|
|
|
// Code generated by ent, DO NOT EDIT.
|
|
|
|
|
|
|
|
package ent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-10-28 23:12:07 +00:00
|
|
|
"online-order/ent/business"
|
2023-10-27 09:51:58 +00:00
|
|
|
"online-order/ent/productcategory"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"entgo.io/ent"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ProductCategory is the model entity for the ProductCategory schema.
|
|
|
|
type ProductCategory struct {
|
|
|
|
config `json:"-"`
|
|
|
|
// ID of the ent.
|
|
|
|
ID int `json:"id,omitempty"`
|
|
|
|
// Name holds the value of the "name" field.
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
// Slug holds the value of the "slug" field.
|
|
|
|
Slug string `json:"slug,omitempty"`
|
|
|
|
// Description holds the value of the "description" field.
|
|
|
|
Description *string `json:"description,omitempty"`
|
|
|
|
// Status holds the value of the "status" field.
|
|
|
|
Status bool `json:"status,omitempty"`
|
2023-10-28 23:12:07 +00:00
|
|
|
// BusinessID holds the value of the "business_id" field.
|
|
|
|
BusinessID *int `json:"business_id,omitempty"`
|
2023-10-27 09:51:58 +00:00
|
|
|
// CreatedAt holds the value of the "created_at" field.
|
|
|
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
|
|
|
// UpdatedAt holds the value of the "updated_at" field.
|
|
|
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
|
|
|
// Edges holds the relations/edges for other nodes in the graph.
|
|
|
|
// The values are being populated by the ProductCategoryQuery when eager-loading is set.
|
|
|
|
Edges ProductCategoryEdges `json:"edges"`
|
|
|
|
selectValues sql.SelectValues
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProductCategoryEdges holds the relations/edges for other nodes in the graph.
|
|
|
|
type ProductCategoryEdges struct {
|
|
|
|
// Products holds the value of the products edge.
|
|
|
|
Products []*Product `json:"products,omitempty"`
|
2023-10-28 23:12:07 +00:00
|
|
|
// Businesses holds the value of the businesses edge.
|
|
|
|
Businesses *Business `json:"businesses,omitempty"`
|
2023-10-27 09:51:58 +00:00
|
|
|
// loadedTypes holds the information for reporting if a
|
|
|
|
// type was loaded (or requested) in eager-loading or not.
|
2023-10-28 23:12:07 +00:00
|
|
|
loadedTypes [2]bool
|
2023-10-27 09:51:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ProductsOrErr returns the Products value or an error if the edge
|
|
|
|
// was not loaded in eager-loading.
|
|
|
|
func (e ProductCategoryEdges) ProductsOrErr() ([]*Product, error) {
|
|
|
|
if e.loadedTypes[0] {
|
|
|
|
return e.Products, nil
|
|
|
|
}
|
|
|
|
return nil, &NotLoadedError{edge: "products"}
|
|
|
|
}
|
|
|
|
|
2023-10-28 23:12:07 +00:00
|
|
|
// BusinessesOrErr returns the Businesses value or an error if the edge
|
|
|
|
// was not loaded in eager-loading, or loaded but was not found.
|
|
|
|
func (e ProductCategoryEdges) BusinessesOrErr() (*Business, error) {
|
|
|
|
if e.loadedTypes[1] {
|
|
|
|
if e.Businesses == nil {
|
|
|
|
// Edge was loaded but was not found.
|
|
|
|
return nil, &NotFoundError{label: business.Label}
|
|
|
|
}
|
|
|
|
return e.Businesses, nil
|
|
|
|
}
|
|
|
|
return nil, &NotLoadedError{edge: "businesses"}
|
|
|
|
}
|
|
|
|
|
2023-10-27 09:51:58 +00:00
|
|
|
// scanValues returns the types for scanning values from sql.Rows.
|
|
|
|
func (*ProductCategory) scanValues(columns []string) ([]any, error) {
|
|
|
|
values := make([]any, len(columns))
|
|
|
|
for i := range columns {
|
|
|
|
switch columns[i] {
|
|
|
|
case productcategory.FieldStatus:
|
|
|
|
values[i] = new(sql.NullBool)
|
2023-10-28 23:12:07 +00:00
|
|
|
case productcategory.FieldID, productcategory.FieldBusinessID:
|
2023-10-27 09:51:58 +00:00
|
|
|
values[i] = new(sql.NullInt64)
|
|
|
|
case productcategory.FieldName, productcategory.FieldSlug, productcategory.FieldDescription:
|
|
|
|
values[i] = new(sql.NullString)
|
|
|
|
case productcategory.FieldCreatedAt, productcategory.FieldUpdatedAt:
|
|
|
|
values[i] = new(sql.NullTime)
|
|
|
|
default:
|
|
|
|
values[i] = new(sql.UnknownType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return values, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
|
|
|
// to the ProductCategory fields.
|
|
|
|
func (pc *ProductCategory) assignValues(columns []string, values []any) error {
|
|
|
|
if m, n := len(values), len(columns); m < n {
|
|
|
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
|
|
|
}
|
|
|
|
for i := range columns {
|
|
|
|
switch columns[i] {
|
|
|
|
case productcategory.FieldID:
|
|
|
|
value, ok := values[i].(*sql.NullInt64)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field id", value)
|
|
|
|
}
|
|
|
|
pc.ID = int(value.Int64)
|
|
|
|
case productcategory.FieldName:
|
|
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field name", values[i])
|
|
|
|
} else if value.Valid {
|
|
|
|
pc.Name = value.String
|
|
|
|
}
|
|
|
|
case productcategory.FieldSlug:
|
|
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field slug", values[i])
|
|
|
|
} else if value.Valid {
|
|
|
|
pc.Slug = value.String
|
|
|
|
}
|
|
|
|
case productcategory.FieldDescription:
|
|
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field description", values[i])
|
|
|
|
} else if value.Valid {
|
|
|
|
pc.Description = new(string)
|
|
|
|
*pc.Description = value.String
|
|
|
|
}
|
|
|
|
case productcategory.FieldStatus:
|
|
|
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field status", values[i])
|
|
|
|
} else if value.Valid {
|
|
|
|
pc.Status = value.Bool
|
|
|
|
}
|
2023-10-28 23:12:07 +00:00
|
|
|
case productcategory.FieldBusinessID:
|
|
|
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field business_id", values[i])
|
|
|
|
} else if value.Valid {
|
|
|
|
pc.BusinessID = new(int)
|
|
|
|
*pc.BusinessID = int(value.Int64)
|
|
|
|
}
|
2023-10-27 09:51:58 +00:00
|
|
|
case productcategory.FieldCreatedAt:
|
|
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
|
|
|
} else if value.Valid {
|
|
|
|
pc.CreatedAt = value.Time
|
|
|
|
}
|
|
|
|
case productcategory.FieldUpdatedAt:
|
|
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
|
|
|
} else if value.Valid {
|
|
|
|
pc.UpdatedAt = value.Time
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
pc.selectValues.Set(columns[i], values[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Value returns the ent.Value that was dynamically selected and assigned to the ProductCategory.
|
|
|
|
// This includes values selected through modifiers, order, etc.
|
|
|
|
func (pc *ProductCategory) Value(name string) (ent.Value, error) {
|
|
|
|
return pc.selectValues.Get(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryProducts queries the "products" edge of the ProductCategory entity.
|
|
|
|
func (pc *ProductCategory) QueryProducts() *ProductQuery {
|
|
|
|
return NewProductCategoryClient(pc.config).QueryProducts(pc)
|
|
|
|
}
|
|
|
|
|
2023-10-28 23:12:07 +00:00
|
|
|
// QueryBusinesses queries the "businesses" edge of the ProductCategory entity.
|
|
|
|
func (pc *ProductCategory) QueryBusinesses() *BusinessQuery {
|
|
|
|
return NewProductCategoryClient(pc.config).QueryBusinesses(pc)
|
|
|
|
}
|
|
|
|
|
2023-10-27 09:51:58 +00:00
|
|
|
// Update returns a builder for updating this ProductCategory.
|
|
|
|
// Note that you need to call ProductCategory.Unwrap() before calling this method if this ProductCategory
|
|
|
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
|
|
|
func (pc *ProductCategory) Update() *ProductCategoryUpdateOne {
|
|
|
|
return NewProductCategoryClient(pc.config).UpdateOne(pc)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unwrap unwraps the ProductCategory entity that was returned from a transaction after it was closed,
|
|
|
|
// so that all future queries will be executed through the driver which created the transaction.
|
|
|
|
func (pc *ProductCategory) Unwrap() *ProductCategory {
|
|
|
|
_tx, ok := pc.config.driver.(*txDriver)
|
|
|
|
if !ok {
|
|
|
|
panic("ent: ProductCategory is not a transactional entity")
|
|
|
|
}
|
|
|
|
pc.config.driver = _tx.drv
|
|
|
|
return pc
|
|
|
|
}
|
|
|
|
|
|
|
|
// String implements the fmt.Stringer.
|
|
|
|
func (pc *ProductCategory) String() string {
|
|
|
|
var builder strings.Builder
|
|
|
|
builder.WriteString("ProductCategory(")
|
|
|
|
builder.WriteString(fmt.Sprintf("id=%v, ", pc.ID))
|
|
|
|
builder.WriteString("name=")
|
|
|
|
builder.WriteString(pc.Name)
|
|
|
|
builder.WriteString(", ")
|
|
|
|
builder.WriteString("slug=")
|
|
|
|
builder.WriteString(pc.Slug)
|
|
|
|
builder.WriteString(", ")
|
|
|
|
if v := pc.Description; v != nil {
|
|
|
|
builder.WriteString("description=")
|
|
|
|
builder.WriteString(*v)
|
|
|
|
}
|
|
|
|
builder.WriteString(", ")
|
|
|
|
builder.WriteString("status=")
|
|
|
|
builder.WriteString(fmt.Sprintf("%v", pc.Status))
|
|
|
|
builder.WriteString(", ")
|
2023-10-28 23:12:07 +00:00
|
|
|
if v := pc.BusinessID; v != nil {
|
|
|
|
builder.WriteString("business_id=")
|
|
|
|
builder.WriteString(fmt.Sprintf("%v", *v))
|
|
|
|
}
|
|
|
|
builder.WriteString(", ")
|
2023-10-27 09:51:58 +00:00
|
|
|
builder.WriteString("created_at=")
|
|
|
|
builder.WriteString(pc.CreatedAt.Format(time.ANSIC))
|
|
|
|
builder.WriteString(", ")
|
|
|
|
builder.WriteString("updated_at=")
|
|
|
|
builder.WriteString(pc.UpdatedAt.Format(time.ANSIC))
|
|
|
|
builder.WriteByte(')')
|
|
|
|
return builder.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProductCategories is a parsable slice of ProductCategory.
|
|
|
|
type ProductCategories []*ProductCategory
|