Advertisement
NameL3ss

logical remove meta-method

Jul 7th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. before_update :remove_logical_relationships
  2.  
  3. def remove_logical_relationships
  4. return if active?
  5.  
  6. self.active = false
  7. exluded_relationships = %i[account]
  8. relationships = self.class.reflect_on_all_associations.map(&:name).reject{|el| exluded_relationships.include?(el)}
  9. relationships.map do |el|
  10. if el.to_s.singularize.eql?(el.to_s)
  11. obj = send(el.to_s.singularize)
  12. obj.update(active: false) if obj.present?
  13. else
  14. send(el.to_s).update_all(active: true)
  15. end
  16. end
  17. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement