pop icon indicating copy to clipboard operation
pop copied to clipboard

Can't call Create(...) using types other than int, int64, UUID or string for primary key

Open mfinley3 opened this issue 4 years ago • 0 comments

Description

Not sure if I am missing something but it appears I cannot call Create(...) with types other than the ones mentioned above. I'd like to be able to. I have an ID type that wraps a few fields, one being a uuid. I'd like to use this type and store the uuid it wraps, as the primary key.

I have both func (id *ID) Scan(src interface{}) error and func (id ID) Value() (driver.Value, error) implemented and they work for Find(), All(), etc... just not Create().

Reasoning for the ID type that is wrapped with other fields is to use a graphql node interface to look up nodes of differing types across a federated schema. This reduces the number of queries that need to written by utilizing a single node(id: ID!): Nodequery. So using just UUID, string, etc isn't really an option for me.

Steps to Reproduce the Problem

  1. Create a table with a pk
  2. Create an ID type that implements both Scan and Value. Making sure the Value function satisfies the tables pk type
  3. Use that ID type as the "db: id" field in a model
  4. Attempt to Create() that resource

Expected Behavior

I'd expexct Create() insert the value into the database using my ID type.

Actual Behavior

I get an error: "can not use ID as a primary key type!"

Info

I'm using pop through buffalo. Right from my go.mod: github.com/gobuffalo/pop/v5 v5.3.0 Related Buffalo pop code: https://github.com/gobuffalo/pop/blob/master/dialect_common.go#L45-L98

mfinley3 avatar Oct 29 '20 00:10 mfinley3