dynamodb-toolbox icon indicating copy to clipboard operation
dynamodb-toolbox copied to clipboard

receive "Error: 'alias' must be a unique string" when overriding created default value

Open jgilbert01 opened this issue 3 years ago • 6 comments

i get this error when trying to override the created/modified default values as shown in the readme to make mocking easier

attributes: {
  ...
  created: { default: () => new Date(Date.now()).toISOString() },
  ...
}

if I switch to this then the override is ignored

attributes: {
  ...
  _ct: { default: () => new Date(Date.now()).toISOString() },
  ...
}

jgilbert01 avatar Sep 13 '20 17:09 jgilbert01

This is likely due to the fact that created is the alias for _ct. I’ll look into this to see if there’s a fix or add it to the documentation.

jeremydaly avatar Sep 14 '20 12:09 jeremydaly

On this topic I get this error when trying to set created as a composite sort key, so I can order by created date.

 created: ['sk', 1],

Not sure if we can look at this at the same time? Let me know if I am using it incorrectly.

Thanks for your great library!

vespertilian avatar Jan 18 '21 06:01 vespertilian

On this topic I get this error when trying to set created as a composite sort key, so I can order by created date.


 created: ['sk', 1],

Have you tried using default instead of composite keys? I moved all of my stuff from composites to defaults because I find it more intuitive/explicit.

darbio avatar Jan 18 '21 07:01 darbio

@darbio

Thanks mate, seems to be a reasonable solution. Also thanks for the quick reply very helpful.

  dependsOn: ['created'],
  default: (data) => `${data.programSubscriptionId}${data.created}`

vespertilian avatar Jan 18 '21 08:01 vespertilian

@jeremydaly the docs for this one still need to be updated

shellscape avatar Oct 04 '21 22:10 shellscape

well, I first tried:

  timestamps: true,
  created: "createdAt",
  modified: "updatedAt",

then I would still get created / modified instead of createdAt / modifiedAt.

so I tried this:

  timestamps: true,
  created: "createdAt",
  modified: "updatedAt",
  createdAlias: "createdAt",
  modifiedAlias: "updatedAt",

and I got an error:

✖ Error: 'alias' must be a unique string

The final solution was:

  timestamps: true,
  attributes: {
   createdAt: { type: "string", dependsOn: ["created"], default: (data) => `${data.created}` },
   updatedAt: { type: "string", dependsOn: ["modified"], default: (data) => `${data.modified}`, onUpdate: true} 
 },

this ended up creating 4 properties: _ct, _mt, createdAt, updatedAt.

any remarks on this??

ahmad-ali14 avatar May 25 '22 11:05 ahmad-ali14