Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error in create nested structure when nested ID is uuid Type that ID is expected to be an integer. #681

Open
abserari opened this issue Dec 10, 2021 · 2 comments
Labels
f: associations the associations feature in pop s: triage Some tests need to be run to confirm the issue

Comments

@abserari
Copy link

Description

If this is a feature request, explain why it should be added. Specific use-cases are best.

For bug reports, please provide as much relevant info as possible.

Steps to Reproduce the Problem

Please describe in painful detail what you did (so others can play along with you) to get to this point. This includes things like the exact command(s) you used, or the curl command you used, that sort of thing.

  1. nested structure is disk
{
  "host_id": "b2312720-242f-4af9-8b2e-a1fe3257052b",
  "os_type": "centos",
  "disks": [
      {
          "id": "dd119bf2-09a2-49ff-8c0e-2f4a20063893"
      }
  ]
}
	err = tx.Create(virtualMachine)
	if err != nil {
		return err
	}
  1. Check for this nested relationship is manytomany
 	Disks Disks `many_to_many:"vms_disks"`

Expected Behavior

Create an entry and create their relationship

Actual Behavior

got an error.

Info

{
    "error": "ERROR: invalid input syntax for type integer: \"14fdf24c-1c29-4f9e-a9ce-f4c55da7a1d5\" (SQLSTATE 22P02)",
    "trace": "ERROR: invalid input syntax for type integer: \"14fdf24c-1c29-4f9e-a9ce-f4c55da7a1d5\" (SQLSTATE 22P02)",
    "code": 500
}

OS:centos8 database: postgreSQL
Use Pop through buffalo

@abserari
Copy link
Author

I found a possible answer is that:
VmsDisk, the relations table of VM and disk, which has an int primary key but pop auto insert with a UUID type.

type VmsDisks struct {
	ID               int       `json:"id,omitempty" db:"id"`
	VirtualMachineID uuid.UUID `json:"virtual_machine_id,omitempty" db:"virtual_machine_id"`
	DiskID           uuid.UUID `json:"disk_id,omitempty" db:"disk_id"`

	CreatedAt time.Time `json:"created_at,omitempty" db:"created_at"`
	UpdatedAt time.Time `json:"updated_at,omitempty" db:"updated_at"`
}

I'll check it later.

@abserari
Copy link
Author

Yes, It means tx.Create or tx.ValidateAndCreate would auto determine that relation table like VmsDisks's ( which is targeted by tag in many to many associations) primary key is UUID type, but not int type with the model target: integer.

Maybe it would be fix with a feature PR?

@sio4 sio4 added f: associations the associations feature in pop s: triage Some tests need to be run to confirm the issue labels Sep 20, 2022
@sio4 sio4 added this to the v6.1.0 milestone Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: associations the associations feature in pop s: triage Some tests need to be run to confirm the issue
Projects
None yet
Development

No branches or pull requests

2 participants