class User < ActiveRecord::Base
has_one :author
+ has_one :artist
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
# Setup accessible (or protected) attributes for your model
attr_accessible :id, :name, :password, :password_confirmation, :remember_me , :email
- before_create do |r|
- r.build_author :name => 'no name'
- end
-
def create_token
self.ensure_authentication_token
self.save
self.save
end
+ def destroy
+ res = false
+ User.transaction do
+ self.author.scrolls.each do |scroll|
+ raise ActiveRecord::Rollback unless scroll.destroy_with_scroll_panel
+ end
+ self.author.panels.each do |panel|
+ raise ActiveRecord::Rollback unless panel.destroy_with_elements
+ end
+ if self.artist
+ self.artist.original_pictures.each do |original_picture|
+ raise ActiveRecord::Rollback unless original_picture.destroy_with_resource_picture
+ end
+ raise ActiveRecord::Rollback unless self.artist.destroy
+ end
+ raise ActiveRecord::Rollback unless self.author.destroy
+ raise ActiveRecord::Rollback unless super
+ res = true
+ end
+ res
+ end
+
end