Skip to content

Commit

Permalink
Refactoring Thesis model scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
martinezo committed Dec 7, 2012
1 parent aaf9b85 commit be9b7f6
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions app/models/thesis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,19 @@ class Thesis < ActiveRecord::Base
where sql
}

scope :roleinthesis_id_eq, lambda { |roleinthesis_id| joins(:user_theses).where(:user_theses => { :roleinthesis_id => roleinthesis_id }) }

scope :as_author, where(:user_theses => {:roleinthesis_id => 1})
scope :roleinthesis_id_eq, lambda { |roleinthesis_id| where(:user_theses => {:roleinthesis_id =>roleinthesis_id }) }
scope :roleinthesis_id_not_eq, lambda { |roleinthesis_id| joins(:user_theses).where{{:user_theses => { :roleinthesis_id.not_eq => roleinthesis_id }}} }
scope :as_author, roleinthesis_id_eq(1)
scope :as_non_author, roleinthesis_id_not_eq(1)
scope :finished, where(:thesisstatus_id => 3).as_non_author
scope :inprogress, where("thesisstatus_id != 3").as_non_author
scope :not_as_author, roleinthesis_id_not_eq(1)

scope :finished, where(:thesisstatus_id => 3).not_as_author
scope :inprogress, where("thesisstatus_id != 3").not_as_author

scope :phd_theses, joins(:career).where('degree_id = 6').as_non_author
scope :mastery_theses, joins(:career).where('degree_id = 5 or degree_id = 4').as_non_author
scope :degree_theses, joins(:career).where('degree_id = 3').as_non_author
scope :technician_theses, joins(:career).where('degree_id = 2').as_non_author
scope :bachelor_theses, joins(:career).where('degree_id = 1').as_non_author
scope :for_phd, joins(:career).where('degree_id = 6').not_as_author
scope :for_master, joins(:career).where('degree_id = 5 or degree_id = 4').not_as_author
scope :for_bachelor_degree, joins(:career_attributeseer).where('degree_id = 3').not_as_author
scope :for_technician, joins(technician_theses:career).where('degree_id = 2').not_as_author
scope :for_high_school, joins(:career).where('degree_id = 1').not_as_author

search_methods :user_id_eq, :user_id_not_eq, :roleinthesis_id_eq

Expand Down

0 comments on commit be9b7f6

Please sign in to comment.