Improved contact deleting

This commit is contained in:
Andres Keskküla 2014-08-18 12:48:28 +03:00
parent 17f7a609cc
commit ef90dfc70b
3 changed files with 61 additions and 6 deletions

View file

@ -71,8 +71,32 @@ class Contact < ActiveRecord::Base
return false
end
def get_relation( model = :domain_contacts )
send(model)
rescue NoMethodError => e
nil
end
def has_relation( model = :domain_contacts )
relation = get_relation(model)
return true unless relation.nil? || relation.blank?
false
end
#should use only in transaction
def destroy_and_clean
clean_up_address
destroy
rescue
errors.add(:contact, msg: I18n.t('errors.messages.epp_command_failed'), value: { obj: 'contact', val: code })
false
end
class << self
def extract_attributes ph, type=:create
contact_hash = {
@ -107,4 +131,11 @@ class Contact < ActiveRecord::Base
end
end
private
def clean_up_address
address.destroy if address
end
end