Created
February 8, 2018 21:11
-
-
Save ornerymoose/39b33252657462a253a38f5acdcf9d44 to your computer and use it in GitHub Desktop.
trying to detect when the number of children an outage has changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Outage < ApplicationRecord | |
has_many :children | |
after_update :if_length_changed | |
def if_length_changed | |
o = Outage.find_by_id(self.id) | |
if (o.children.any?(&:changed?) || o.children.collect(&:id).sort != o.children.pluck(&:id).sort) | |
puts "\n\nlength was changed, count: #{o.children.count}\n\n" | |
else | |
puts "\n\nnotchanged, count: #{o.children.count}\n\n" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment