Permalink
Browse files

Refactoring Thesis model scopes

  • Loading branch information...
1 parent aaf9b85 commit be9b7f65dfd654e315d2a1e2dc4bc3fff4b21c8d @martinezo martinezo committed Dec 7, 2012
Showing with 10 additions and 11 deletions.
  1. +10 −11 app/models/thesis.rb
View
@@ -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

0 comments on commit be9b7f6

Please sign in to comment.