How can I set up “timestamps()” so that it inserts “nil” by default in updated_at?
Nobody knows?
Check out the autogenerate
option: https://hexdocs.pm/ecto/Ecto.Schema.html#timestamps/1
I think you have to work with that manually.
I’m afraid that you can’t do that according to this note.
In theory you could send option like this: timestamps(updated_at: false)
which wouldn’t create this column and you could insert it with different type than any datetime e.g. add :updated_at, :string
, but it would be over engineering.
If you want to track whether struct was updated, you have several options to do that, but each of them is related to process data from DB, but not do any operation directly on DB level:
- compare
inserted_at
withupdated_at
- add custom flag
is_updated?
or something similar
I hope it will help you.
But that will adjust both columns - updated and inserted whereas I need only “updated”.
Check the args given to that function if you can differentiate based on them. Otherwise I think you will need to do it by yourself without timestamps
.