suck it! one down, lots to go.
[kwestie.git] / app / models / issue.rb
blobe3ebeddae871257181ff5218ff80bde270f4971b
1 class Issue < ActiveRecord::Base
2   usesguid
4   before_destroy { |issue| Permalink.destroy_all "issue_id = '#{issue.id}'" }
6   belongs_to :permalink
7   belongs_to :created_by, :class_name => "User", :foreign_key => "created_by"
9   has_many :comments, :dependent => :destroy, :order => "comments.created_at ASC"
10   has_many :all_permalnks, :class_name => "Permalink", :foreign_key => "issue_id", :dependent => :destroy
12   has_many :attachments, :class_name => "Attachment", :foreign_key => "issue_id", :dependent => :destroy
14   validates_presence_of :title, :description
16   def year
17     self.created_at.year()
18   end
20   def month
21     self.created_at.strftime("%m") # month() with leading zero
22   end
24   def day
25     self.created_at.strftime("%d") # day() with leading zero
26   end
28   # FIXME: we should be checking that the title has changed significantly, not just that it has been edited
29   def title=(new_title)
30     write_attribute(:title, new_title)
31     create_permalink
32   end
34   private
35     def create_permalink()
36       return if self.id.nil?
37       self.permalink = Permalink.create( { :link_name => self.title, :issue_id => self.id } )
38       self.save
39     end
40 end