approach for tracking changes for an object

11 views
Skip to first unread message

Koray Taylan Davgana

unread,
Nov 5, 2011, 9:54:52 AM11/5/11
to datam...@googlegroups.com
hi,

I have a common model named Post with obvious attributes like title, content, etc. I'm using dm-timestamps so I have created_at, updated_at automatically generated but I also want to track the evolution of a specific Post.

first solution coming to my mind is to create a clone table named like post_log and set a sql trigger for updates which takes a snapshot of current state of that object into log table so when I query with a specific id from post_log table then I can see what happened in time for that object. but after getting more and more familiar with datamapper I feel like I supposed to use coding first approach rather than tying myself into database because it feels more comfortable to let datamapper handle db creating/altering jobs. I saw in the documents that I can add some logic into Model's save process. but I'm not sure if it is a good idea or not and I wonder what approach do you guys use for tracking changes.

thanks,
koray.

Koray Taylan Davgana

unread,
Nov 5, 2011, 4:29:41 PM11/5/11
to datam...@googlegroups.com
after I wrote this post I found that there is a plugin named 'dm-is-versioned' which is doing what I mentioned.

I put is_versioned :on => :updated_at on my Post model and it creates a new row in post/version table. great!

however, it seems to be an issue with dm-timestamps plugins because if I don't put

before(:save) { self.updated_at = Time.now }

in model, it doesn't catch the event somehow.

anyways, problem solved :)

thanks,
koray.
Reply all
Reply to author
Forward
0 new messages