How to update records without triggering the updatedAt timestamp? #1642
-
|
Hello, V 2.5.1 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
|
On the update method, there is an argument called allowExplicitTimestamps. You can set that to true and force the old updatedAt like so: post = model("post").findByKey(params.key);
post.update(
createdAt=post.createdAt,
updatedAt=post.updatedAt,
deletedAt=post.deletedAt,
properties=PARAMS.post
);This example of course assumes the post params you need to update are coming in through a post struct in your PARAMS. |
Beta Was this translation helpful? Give feedback.
-
|
Sorry, I misunderstood. The cleanliness: allowExplicitTimestamps is part of the update() function — I have this code, but it doesn’t work. local.user = model("user").findByKey(key=session.user.id); |
Beta Was this translation helpful? Give feedback.
-
|
@Renand Thanks for reporting this. We’ve tested it and were able to reproduce the issue as well. We’re actively working on a fix and will keep you updated. Appreciate you bringing this to our attention. |
Beta Was this translation helpful? Give feedback.
@Renand The approach shown here (using the update() method with the
allowExplicitTimestampsargument to prevent updatedAt from being changed) does work in the latest Wheels 3.0 version. Wheels 3.0 includes the underlying feature that lets you explicitly set timestamp columns withallowExplicitTimestamps=truewhen updating records — so you can keep your updatedAt value untouched when needed.