Mercurial > hg > soundsoftware-site
annotate vendor/plugins/redmine_bibliography/app/models/publication.rb @ 557:2fe129b04d82 feature_36
Fixes Bug #222.
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Wed, 03 Aug 2011 16:09:27 +0100 |
parents | ca9e8e562ea7 |
children | 3c9ca235835b |
rev | line source |
---|---|
luis@385 | 1 # vendor/plugins/redmine_bibliography/app/models/publication.rb |
luis@385 | 2 |
luis@328 | 3 class Publication < ActiveRecord::Base |
luis@428 | 4 unloadable |
luis@445 | 5 |
luis@468 | 6 has_many :authorships, :dependent => :destroy |
luis@447 | 7 has_many :authors, :through => :authorships, :uniq => true |
luis@446 | 8 |
luis@445 | 9 has_one :bibtex_entry, :dependent => :destroy |
luis@376 | 10 |
luis@376 | 11 validates_presence_of :title |
luis@445 | 12 |
luis@445 | 13 accepts_nested_attributes_for :authorships |
luis@446 | 14 accepts_nested_attributes_for :authors, :allow_destroy => true |
luis@454 | 15 accepts_nested_attributes_for :bibtex_entry, :allow_destroy => true |
luis@454 | 16 |
luis@464 | 17 has_and_belongs_to_many :projects, :uniq => true |
luis@428 | 18 |
luis@556 | 19 after_save :set_initial_author_order |
luis@556 | 20 |
luis@556 | 21 def set_initial_author_order |
luis@556 | 22 authorships = self.authorships |
luis@556 | 23 |
luis@556 | 24 logger.debug { "Publication \"#{self.title}\" has #{authorships.size} authors." } |
luis@556 | 25 |
luis@556 | 26 authorships.each_with_index do |authorship, index| |
luis@556 | 27 if authorship.auth_order.nil? |
luis@556 | 28 authorship.auth_order = index |
luis@556 | 29 authorship.save! |
luis@556 | 30 end |
luis@556 | 31 end |
luis@556 | 32 end |
luis@556 | 33 |
luis@556 | 34 |
luis@556 | 35 |
luis@556 | 36 |
luis@328 | 37 end |