smpallen99 / whatwasit

Track changes to your Ecto models
MIT License
63 stars 8 forks source link

Add map for additional data e.g data of request #10

Closed Eiji7 closed 8 years ago

Eiji7 commented 8 years ago

I want to save more data that is not stored in User model e.g request data. For example:

  1. Store map with IP address to easily detect what changes was made from particular IP.
  2. Store user agent for statistics.
smpallen99 commented 8 years ago

This can be achieved pretty easy already with the whodoneit-map install option. For example, in the example in the readme file, you can modify the defp whodoneit(conn) do function to create your own map, including with what ever data you want.

I don't think an additional map is required.

Eiji7 commented 8 years ago

Can I keep relation belongs_to to User and store map of additional data at same time? I need one more query for each version instead of querying by relations.

smpallen99 commented 8 years ago

Is there a good reason to do so? Can you give an example that warrants having both a module model reference and a separate map of additional data. I'm a little hesitant since it adds additional complication and I want to make sure there is a good use case for it.

Eiji7 commented 8 years ago

For example: I know Mike. He is good editor and my friend from real world, but his account was hacked (e.g "Social engineering").

  1. I want to retrieve list all changes made by Mike to sum his job and send payment.
  2. I want to retrieve list all changes made by hacker IP (stored in request map) to detect unwanted system changes and revert them.
  3. We have trainee. He is temporary editor, but he has problem with grammar. We need to delete his account and all changes that was made by him (has_many reference).
smpallen99 commented 8 years ago

So, what wrong with using the whodoneit-map option and store the following map? %{user_id: user.id, request_ip: header.ip, username: user.username, ...}

Eiji7 commented 8 years ago

See: Add dependent opts #723. I want to use dependent for versions (see example in point 3 of my comment above).