Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated_at timestamp is filled on create #300

Closed
circulon opened this issue Jan 7, 2021 · 6 comments
Closed

updated_at timestamp is filled on create #300

circulon opened this issue Jan 7, 2021 · 6 comments

Comments

@circulon
Copy link
Contributor

circulon commented Jan 7, 2021

Just updated to 1.0.0 YAY!

Noticed an issue when using .create that the updated_at field gets the same timestamp as created_at when creating a new model.

Haven't had time to investigate this yet so I'm just adding it here

@josephmancuso
Copy link
Member

Thats correct and intended behavior. Thats how other ORM's I have used work as well

@josephmancuso
Copy link
Member

josephmancuso commented Jan 7, 2021

If the updated_at is set on create then when sorting by updated_at, this way the unmodified records will be placed between the modified ones when sorting by updated_at.

We could create a way to unset this behavior via a model attribute but I would advise against it. Is there a reason you would want this?

@circulon
Copy link
Contributor Author

circulon commented Jan 7, 2021

Hi Joe

Thanks for the clarification on this. I was expecting the updated_at column to be empty (NULL) on initial record creation as this would indicate it had never been updated.

As this is expected and I now understand the reasoning behind it, You can close this issue.

Thanks for the clarification and keep up the great work.

@circulon
Copy link
Contributor Author

circulon commented Jan 7, 2021

Oops Didnt realise I could close this ;)

@circulon circulon closed this as completed Jan 7, 2021
@josephmancuso
Copy link
Member

josephmancuso commented Jan 7, 2021

Yeah. When I researched this a bit I found some different opinions but most were sorta closed out and made it seem like they stayed with the default behavior. To get records that are not updated you can do something like this:

User.where_column('updated_at', '=', 'created_at')

and records updated:

User.where_column('updated_at', '>', 'created_at')

@circulon
Copy link
Contributor Author

circulon commented Jan 8, 2021

Yeah I figured that out after you clarified the usage pattern

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants