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!
Popular in Chat/Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








