I have the following table:
event_id value created_at updated_at
1 15.2 2014/01/01 00:00 2014/01/01 00:00
2 15.5 2014/01/01 00:10 2014/01/01 00:10
3 15.9 2014/01/01 00:20 2014/01/01 00:20
However, if a new Event has same value as the previous (as in newest in time) Event, then the previous Event should have "updated_at" set to current time and no new Event should be created.
In the example above, if I do Event.new(:value => 15.9), then Event with id 3 should have its updated_at set to current time - and that should be the only change.
Any suggestions on how to accomplish this? I have tried fiddling with Active Record callbacks, but fail when aborting creation (using rollback). It is of course possible to solve using a special "constructor" method, but I'd like to avoid that.