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

sadcad
I love the Phoenix and Elixir docs, but I always tend to learn faster when I watch a video of someone explaining things and then I implem...
New
Fl4m3Ph03n1x
Background Hey guys, recently I bought a book on TDD that I am reading. The books is really nice and has some really juicy things on arch...
New
Iex.new
Hello!, I just started this week to discover Elixir. I’m a PHP-Programmer and did some sutff in Go too. The more I read about Elixir t...
New
nur
https://e.planaria.network Build a NoSQL DB, Build a Relational SQL Database, Build a Graph Database, Build a File System, Build a Bitc...
New
miguelsrrobo
hi i was wondering if it is necessary to learn erlang to learn elixir
New
boddhisattva
Greetings everyone, At my current workplace we’re evaluating different ways of building a microservices architecture for some parts rela...
New
asfand
Hi Everyone, I am a student and know basics of web development, used some php and ruby, but I am not an expert in any. I want to learn E...
New
Fl4m3Ph03n1x
Background After following the communitiy suggestion, I bought the Elixir in Action 2nd Edition book and I am about to finish it now. I ...
New
svetarosemond
I’m planning on purchasing Elixir in action second edition, and I was wondering if anyone could tell me based off the first edition, does...
New
Nopp
Hello there, i have a lot to read and to learn, but are there some books, that are focussing on how i “should” plan the architecture of ...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New

We're in Beta

About us Mission Statement