Add 'revision' attribute to Conference, managed by an observer
This commit is contained in:
parent
27017a4823
commit
d648ab7cb5
4 changed files with 34 additions and 1 deletions
26
app/models/revision_observer.rb
Normal file
26
app/models/revision_observer.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#
|
||||
# suseconferenceclient relies on a 'revision' attribute for caching and
|
||||
# doing some calculations.
|
||||
#
|
||||
# It should be incremented after any change in the conference or in any
|
||||
# associated models
|
||||
#
|
||||
# This observer updates the revision column in a non-intrusive way,
|
||||
# preventing validations, callbacks or exceptions to be triggered
|
||||
#
|
||||
# Relying on paper_trail could also be an option, but a 'revision' column
|
||||
# in table 'conferences' looks like a more simple and straightforward solution
|
||||
#
|
||||
class RevisionObserver < ActiveRecord::Observer
|
||||
observe :conference, :event, :room, :social_event, :track
|
||||
|
||||
def after_save(model)
|
||||
begin
|
||||
conference = model.kind_of?(Conference) ? model : model.conference
|
||||
conference.reload.increment(:revision)
|
||||
conference.update_column(:revision, conference.revision)
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue