1
  type Order struct{
      Id uint `json:"id"`
      Items []Item
      Total float64
      CustomerID int32
      Address Address
      CreatedAt time.Time
      UpdatedAt time.Time
      Status orderstatus
    }

query := INSERT INTO orders(items, total, address, customer_id, status, created_at) VALUES(@orderItems,@orderTotal,@orderAddress,@orderCustomerID, @orderStatus,@orderCreatedAt) returning id, total, customer_id;

 trans := pgx.NamedArgs{
          "orderItems": items,
          "orderTotal": float64(grandtotal),
          "orderAddress": address,
          "orderCustomer" : id,
          "orderStatus" : "Pending",
           "orderCreatedAt" : time.Now(),
          }

    err := database.DB.QueryRow(context.Background(),query,trans)
         .Scan(&order.Id, &order.Total, &order.CustomerID)
  

whenever i scan the customerID i get the error saying it cant be converted into a struct the customerID references Users(id) i tried to write struct that mentioned CustomerID as type of User and it failed too any help is highly appreciated #golangbeginner

0 Answers0