Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capturing old values for model in MVC3?

I'm wanting to capture the old values within a model so I can compare with the new values after submission, and create audit logs of changes a user makes.

My guess is doing it with hidden input boxes with duplicated old value properties would be one way. But wondering if there are any other good alternatives?

Thanks

like image 286
stats101 Avatar asked May 24 '12 16:05

stats101


2 Answers

In the save method, just go and get the original object from the database before saving the changes, then you have your old and new values to compare against? :)

like image 108
mattytommo Avatar answered Sep 28 '22 07:09

mattytommo


This sounds like standard auditing. You should not worry about what has changed just capture EVERYTHING and who made the change. Unless there is some sort of real time reporting that needs to be done.

Possible auditing implementations:

CQRS, in a nutshell it tracks every change to a given object. The downside is it's an architecture that is more involved to implement.

The Rolling ledger. Each insert is a new row in the database. The most current row is used for display purposes, but with each update, a new row is inserted into the database.

Yet another approach is to save it off into an audit table.

All get the job done.

like image 44
Chuck Conway Avatar answered Sep 28 '22 06:09

Chuck Conway