blob: 10f3077ed61623fb716e7d827e30ef5bcb950ab9 [file] [log] [blame]
# == Schema Information
# Schema version: 1
#
# Table name: comments
#
# id :integer(11) not null, primary key
# text :text
# ip_address :string(500)
# done :string(1) default(N), not null
# user_id :integer(10) default(0), not null
# page_id :integer(10)
# site_id :integer(10)
# version_id :integer(10) default(0), not null
# baseline_id :integer(11) default(0), not null
# created_on :datetime
# updated_on :datetime
# reviewer_id :integer(11)
# user_id_markdone :integer(11)
# user_id_marktodo :integer(11)
#
require_dependency "search_system"
# A Comment belongs Page and is created within the context of a Site by a specific User.
# There is redundancy here as also the Version of the Page is recorded with a Comment.
# Because the Baseline of a Site can change in time, the Comment also belongs to a Baseline.
#
# More information:
# * {EPF Wiki Data model}[link:files/doc/DATAMODEL.html]
#--
# TODO R? validate submitted html (all tags closed etc)
#++
#--######################################################################
# Copyright (c) 2006 LogicaCMG
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
#
# Onno van der Straaten:: initial implementation
#++######################################################################
# {Copyright (c) 2006 LogicaCMG}[link:files/COPYRIGHT.html]
class Comment < ActiveRecord::Base
belongs_to :site
belongs_to :baseline
belongs_to :user
belongs_to :reviewer, :class_name => "User", :foreign_key => "reviewer_id"
belongs_to :page, :counter_cache => true
belongs_to :version
belongs_to :user_thatmarkeddone, :class_name => "User", :foreign_key => "user_id_markdone" #:doc:
belongs_to :user_thatmarkedtodo, :class_name => "User", :foreign_key => "user_id_marktodo" #:doc:
validates_presence_of :text, :user, :version, :page, :baseline, :site
make_searchable [:text]
def before_validation_on_create
if self.version.nil?
self.version = Version.find_current_version(self.site, self.page, true)
else
self.page = self.version.page if self.page.nil?
self.site = self.version.site if self.site.nil?
self.baseline = self.site.baseline if self.baseline.nil?
end
self.baseline = self.site.baseline if self.baseline.nil?
end
end