keystone-classic
keystone-classic copied to clipboard
findOneAndUpdate does not update tracked fields if upserted
Expected behavior
Calling findOneAndUpdate
and creating a new document (while upsert
is set to true
) as a result of the function should also update the tracked createdAt
and createdBy
fields
Actual/Current behavior
It does not update createdAt
or createdBy
. They are both undefined
.
Steps to reproduce the actual/current behavior
- Implement a
findOneAndUpdate
function call on a Keystone model. - Pass it a first argument that represents a document that does not exist.
- Pass it a second argument that represents what data the document should have.
- Let the function run.
- Look at the document in the Admin panel, or retrieve the document some other way.
-
createdAt
andcreatedBy
are bothundefined
.
I can manually instantiate these fields by passing createdAt
and createdBy
to the second argument of findOneAndUpdate
, but the createdAt
date will always update to be whenever the document was updated, rather than being maintained. Using findOneAndUpdate
, I've no way of knowing whether this document exists before including this condition.
Environment
Software | Version |
---|---|
Keystone | 4.0.0-beta.5 |
Node | 6.9.1 |
I think this is related to #854, but I don't know if they're the same issue.
@SHBelsky I think it's the same issue. It still hasn't been implemented. Any chance you can assemble a PR?
I'll see if I can track down the cause, and make a PR when that happens!
Having this issue also with the updatedAt field