Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- before_update :remove_logical_relationships
- def remove_logical_relationships
- return if active?
- self.active = false
- exluded_relationships = %i[account]
- relationships = self.class.reflect_on_all_associations.map(&:name).reject{|el| exluded_relationships.include?(el)}
- relationships.map do |el|
- if el.to_s.singularize.eql?(el.to_s)
- obj = send(el.to_s.singularize)
- obj.update(active: false) if obj.present?
- else
- send(el.to_s).update_all(active: true)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement