Alex Antonov
Alex Antonov

Reputation: 15216

How to update model without touching updated_at in ecto?

I have pretty simple code which changes only on column, like:

content = Content
  |> Repo.get(1)

content
|> Ecto.Changeset.change(%{ views_count: content.views_count + 1 })
|> Repo.update

I don't want this code to change its views count, but I don't want to touch updated_at field. How can I do that?

Upvotes: 1

Views: 1679

Answers (1)

NoDisplayName
NoDisplayName

Reputation: 15746

I am not sure I understood the question but this may work:

Content
|> where(id: 1)
|> Repo.update_all(inc: [views_count: 1])

Upvotes: 8

Related Questions