annotate plugins/redmine_bibliography/app/models/author.rb @ 1621:3a510bf6a9bc

Merge from live branch
author Chris Cannam
date Fri, 13 Jul 2018 10:44:33 +0100
parents b688fe79f593
children
rev   line source
luis@328 1 class Author < ActiveRecord::Base
luis@946 2 unloadable
luis@1123 3
luis@468 4 has_many :authorships, :dependent => :destroy
luis@328 5 has_many :publications, :through => :authorships
luis@403 6
luis@466 7 belongs_to :user
luis@478 8
luis@478 9 def <=>(author)
luis@478 10 name.downcase <=> author.name.downcase
luis@478 11 end
luis@1123 12
luis@1124 13 # todo: review usage of scope --lf.20130108
luis@1123 14 scope :like, lambda {|q|
luis@477 15 s = "%#{q.to_s.strip.downcase}%"
luis@477 16 {:conditions => ["LOWER(name) LIKE :s", {:s => s}],
luis@477 17 :order => 'name'
luis@477 18 }
luis@478 19 }
luis@478 20
luis@1412 21 def institution
luis@1413 22 if self.authorships.first.nil?
luis@1413 23 ""
luis@1413 24 else
luis@1413 25 self.authorships.first.institution
luis@1413 26 end
luis@1412 27 end
luis@1414 28
luis@1414 29 def mail
luis@1414 30 if self.authorships.first.nil?
luis@1414 31 ""
luis@1414 32 else
luis@1414 33 self.authorships.first.mail
luis@1414 34 end
luis@1414 35 end
luis@1414 36
luis@1420 37 # todo: need to fix the name getter
luis@1417 38 def name
luis@1420 39 if self.authorships.first.nil?
luis@1420 40 ""
luis@1420 41 else
luis@1420 42 self.authorships.first.name
luis@1417 43 end
luis@1417 44 end
luis@1417 45
luis@328 46 end