luis@328: class Author < ActiveRecord::Base luis@946: unloadable luis@1123: luis@468: has_many :authorships, :dependent => :destroy luis@328: has_many :publications, :through => :authorships luis@403: luis@466: belongs_to :user luis@478: luis@478: def <=>(author) luis@478: name.downcase <=> author.name.downcase luis@478: end luis@1123: luis@1124: # todo: review usage of scope --lf.20130108 luis@1123: scope :like, lambda {|q| luis@477: s = "%#{q.to_s.strip.downcase}%" luis@477: {:conditions => ["LOWER(name) LIKE :s", {:s => s}], luis@477: :order => 'name' luis@477: } luis@478: } luis@478: luis@1412: def institution luis@1413: if self.authorships.first.nil? luis@1413: "" luis@1413: else luis@1413: self.authorships.first.institution luis@1413: end luis@1412: end luis@1414: luis@1414: def mail luis@1414: if self.authorships.first.nil? luis@1414: "" luis@1414: else luis@1414: self.authorships.first.mail luis@1414: end luis@1414: end luis@1414: luis@1420: # todo: need to fix the name getter luis@1417: def name luis@1420: if self.authorships.first.nil? luis@1420: "" luis@1420: else luis@1420: self.authorships.first.name luis@1417: end luis@1417: end luis@1417: luis@328: end