Update another entities timestamp (updated_at)

When updating/inserting a model (namely note) I need Phoenix to update updated_at field of the related model (notepad). There is a ∞:1 relationship between notes and notepads.

I’ve came up with a solution to touch the notepad or simply set its updated_at field to the current datetime, but this seems like a dirty hack, thus I’m looking for a more elegant solution.

I would go explicit, like what you have right now. Don’t rely on hidden black-boxes or methods with side-effects because it hurts long-term productivity.

In your method when you update a note, call a method named MyApp.Notepad.touch(note_id)

Explicit is good :smiley:

3 Likes

Thanks. That’s what I’ll do (:

This may be relevant:

You can pass a force: true option when you call Repo.update with an empty changeset and that should be enough.

https://groups.google.com/g/elixir-ecto/c/hb3T9g_N_Gw