question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

created_at field always updated when call save() method

See original GitHub issue

UserController.js

"use strict";

const User = use("App/Models/User");
const Hash = use("Hash");

class UserController {
  async store() {
    const user = new User();
    user.username = "abc";
    user.email = "abc@gmail.com";
    user.password = await Hash.make("abc");
    return await user.save();
  }

  async show({ params }) {
    const { id } = params;
    return await User.find(id);
  }

  async update({ params }) {
    const { id } = params;
    const user = await User.find(id);
    user.username = "abc";
    user.email = "abc@gmail.com";
    user.password = await Hash.make("abc");
    return await user.save();
  }
}

module.exports = UserController;

I’m using fresh install of adonis, and mssql Azure as the database connection after saving data using save() the created_at field updated to another value, check my video

Video

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
JesterIrukacommented, May 27, 2021

I’m having the same issue, but I noticed that my table being created like this

I fixed using this:

      table.timestamp('created_at').defaultTo(this.now()) // without defaultTo is the same as timestamps()
      table.timestamp('updated_at')
3reactions
hiukkycommented, Aug 28, 2019

I have this same problem … I am using MSSQL and saving the records using the save () method. apparently when creating the record it saves with the correct dates … but in the update process the new dates no longer match … it also changes the created_at date whenever the save () method is executed …

Read more comments on GitHub >

github_iconTop Results From Across the Web

add created_at and updated_at fields to mongoose schemas
The created_at field would be a date and only added when a document is created. The updated_at field would be updated with new...
Read more >
How to persist creation and update timestamps with ...
You need a simple, fail-safe solution that automatically updates the timestamp for each and every change. As so often, there are multiple ways...
Read more >
How to update createdAt and updatedAt fields in your data ...
One solution would be to have an "Update Audit Fields" node in your process model before your data write. Here, you could save...
Read more >
JavaScript Developers Guide | Parse
Updating an object is simple. Just set some new data on it and call the save method. For example: // Create the object....
Read more >
Django Tips #4 Automatic DateTime Fields
The auto_now_add will set the timezone.now() only when the instance is created, and auto_now will update the field everytime the save method is ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found