Tracking changes to class instances and their associations - thoughts?

I have a Question class that has many related models. On one page of my application, I list a summary of all current issues with various information from related entries. Ultimately, this is a hash of the values, which I then simply print in the csv style string (I will call it a “hash string” from here)

Now I have a requirement only to show changes in questions (or related data) for a certain period. I am currently considering the best way to do this. Here are some ideas that I have had so far, I would welcome any feedback, thoughts, suggestions, etc.

1) Approach 1 - act_as_audited This was my first thought, since I used it before in other applications. However, the problem with aaa is that it only tracks changes in the record data (i.e., it doesn't matter if the association changes). That way, I could also check all related records, but then, trying to combine what has changed, linking different audit records, sounds like a nightmare.

2) Save the old and new hash in serialized fields: ie - when someone goes to the question / edit page, I calculate the current hash of the line and save it in the serialized field "old_data" in the question table. Then, after saving the question, I calculated a new hash of the current line and saved it in the serialized field "new_data" in the question table. In addition, I compare the two serialized hashes and store the differences in another serialized hash field of the “change” hash. Now, to make my report, I'm just looking for questions updated over the last x days, and the output of their change data.

3) - , , (.. , ). - -. , .

2.

/? - .

+3
3

, , x y, ? act_as_audited, , ? has_many_through- , , X. . , , - , - , , . , , , ?

+1

, , . , Mongoid Mongomapper, .

+1

, . , , , . () , . , , .

None of the plugins that I saw could really do this simply and efficiently, so I ended up creating a table called states that simply contains a serialized hash with the results of all these method calls. This is preserved when changing and saving a record or when changing and saving any of the corresponding related objects. Then I have some methods to return the differences between the various stored state records. This works well for my needs. Anyway, thanks for your advice.

0
source

Source: https://habr.com/ru/post/1754578/


All Articles