35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/acts_as_aliased.rb', line 35
def to_alias! aliased
raise "Cannot create alias for myself" if aliased == self
self.class.transaction do
a = ::ActsAsAliased::Alias.create(aliased: aliased, name: self[column])
associations.each do |association|
klass = association.to_s.classify.constantize
key = self.class.to_s.foreign_key
klass.where(key => id).update_all(key => aliased.id)
end
Alias.where("aliased_type = ? AND aliased_id = ?", self.class.to_s, self.id).update_all(aliased_id: aliased.id)
self.destroy
return a
end
end
|