DB: Integridade referencial

This commit is contained in:
2008-03-06 05:43:56 -03:00
parent e5bc6024ba
commit c58684c31c
12 changed files with 88 additions and 68 deletions

View File

@@ -13,23 +13,32 @@
class Course < ActiveRecord::Base
has_many :attachments, :order => "file_name"
has_many :wiki_pages, :order => "position"
has_many :shoutbox_messages,
:class_name => 'CourseShoutboxMessage',
:foreign_key => "receiver_id",
:order => 'id desc'
# Associacoes
has_many :attachments,
:order => "file_name",
:dependent => :destroy
has_many :events,
:order => "time asc",
:dependent => :destroy
has_many :news,
:class_name => 'News',
:foreign_key => "receiver_id",
:order => 'id desc'
:order => "id desc",
:dependent => :destroy
has_many :events, :order => "time asc"
has_many :log_entries,
:order => "created_at desc",
:dependent => :destroy
has_many :log_entries, :order => "created_at desc"
has_many :wiki_pages,
:order => "position",
:dependent => :destroy
# Plugins
acts_as_paranoid
# Validacao
generate_validations
validates_uniqueness_of :short_name
validates_format_of :short_name, :with => /^[^0-9]/
@@ -41,15 +50,6 @@ class Course < ActiveRecord::Base
end
end
def after_destroy
associations = [:attachments, :wiki_pages, :shoutbox_messages, :news, :events]
associations.each do |assoc|
send("#{assoc}").each do |record|
record.destroy
end
end
end
def to_param
self.short_name
end