lolopinto / ent

MIT License
51 stars 6 forks source link

UUIDType fields within StructType[AsList] fields do not get saved on mutation #1740

Closed Swahvay closed 8 months ago

Swahvay commented 9 months ago

If I have the following field definition:

horses: StructTypeAsList({
  tsType: 'CompetitionEventHorseEntry',
  fields: {
    horseID: UUIDType({
      nullable: true,
      foreignKey: {
        schema: 'Horse',
        column: 'ID',
      },
    }),
    horseName: StringType({
      nullable: true,
      maxLen: 200,
    }),
  },
}),

Then in a create, the horseName field will be saved to the ent, but not the horseID field. Setting the same ID value on a field in that ent that is not part of a StructType works correctly.

Swahvay commented 8 months ago

I'm gonna try to do some digging on this one, since it's actually quite blocking for me. I was surprised this was the first time I'd actually put a UUID field on a StructType.

Swahvay commented 8 months ago

Found the problem.

https://github.com/lolopinto/ent/blob/d5cd985ea38c9d06695e08940187ccbd9950b328/ts/src/schema/struct_field.ts#L84

Here camelKey comes back as horseId so val = obj[camelKey] always sets val to undefined.