wimwian

wimwian

ecto schema created_by and last_modified_by

Hi,

I have a requirement to track the user who created the record and the user who last updated the record for audit purposes.

I have added two fields to the schema (created_by and last_modified_by).

I was checking the timestamps() code in ecto git repository to understand how I could update the values in these attributes where I noticed two module attributes (ecto_autogenerate and ecto_autoupdate).

My understanding is that ecto_autogenerate is triggered when autogenerate is set to true or a {module, function, attributes} tuple is set for the field in schema definition.

Also, another thought was autogenerate will be triggered at insert while autoupdate shall be trigged at update, However, I could not find any documenration on ecto_autoupdate except for these three lines of code in schema.ex

find . -name “*.ex” -print | xargs grep -in ecto_autoupdate
./lib/ecto/schema.ex:438: Module.register_attribute(MODULE, :ecto_autoupdate, accumulate: true)
./lib/ecto/schema.ex:522: autoupdate = @ecto_autoupdate |> Enum.reverse
./lib/ecto/schema.ex:654: Module.put_attribute(MODULE, :ecto_autoupdate, {[updated_at], autogen})

Can someone explain how the ecto_autoupdate attribute is expected to work?

Thank you!

Where Next?

Popular in Chat/Questions Top

nur
https://e.planaria.network/stack.png https://e.planaria.network Build a NoSQL DB, Build a Relational SQL Database, Build a Graph Datab...
New
armanm
I know zero downtime deployment can mean different things depending on your application and what your users can tolerate so expectations ...
New
jsnoble
I come from a javascript background and I just starting learning elixir. I went through the basic tutorials but I want something deeper. ...
New
eliottramirez
Hello, I’m trying to learn Phoenix but I constantly find difficult understanding how the framework works, and I think part of this is th...
New
mchean
I was wondering if anyone is using some learning tools that they can recommend? I’ve been looking at two specifically so would also be ...
New
gouvermxt
I just finished the “Learn Functional Programming with Elixir (Pragprog)” book. I have 5+ years of experience with Ruby/Rails, my goal is...
New
TwistingTwists
I want to learn DSL. Don’t know how to write one. What;s the best introductory resource? I see some macro being used here. Is DSL only ...
New
wallyfoo
Long story short, I have a real world need to create a view for hooking up a shipping terminal to live data, but because of some early ar...
New
Fl4m3Ph03n1x
GenStage and Flow resources? I have been hearing about GenStage and Flow, a tool built upon it, for quite some time. I understand it allo...
New
shansiddiqui94
Hello, I have an interview coming up and I seem to have forgotten important concepts of Elixir. So I was wondering if you guys know of a...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement