Skip to content

Commit

Permalink
fix deprecation warnings relating to has_many declarations
Browse files Browse the repository at this point in the history
DEPRECATION WARNING: The following options in your ResponseSet.has_many :responses declaration are deprecated: :order. Please use a scope block instead.

We use instance_eval because we need the scope lambda to run in the
context of the including Class, not the Module in which the code is
defined.
  • Loading branch information
toby cabot committed Aug 15, 2013
1 parent ade06ea commit 33a9f62
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/surveyor/models/response_set_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def self.included(base)
# Associations
base.send :belongs_to, :survey
base.send :belongs_to, :user
base.send :has_many, :responses, :order => "#{Response.quoted_table_name}.created_at ASC", :dependent => :destroy
base.instance_eval {has_many :responses, ->{order "#{Response.quoted_table_name}.created_at ASC"}, :dependent => :destroy}
base.send :accepts_nested_attributes_for, :responses, :allow_destroy => true

@@validations_already_included ||= nil
Expand Down
4 changes: 2 additions & 2 deletions lib/surveyor/models/survey_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module Models
module SurveyMethods
def self.included(base)
# Associations
base.send :has_many, :sections, :class_name => "SurveySection", :order => "#{SurveySection.quoted_table_name}.display_order", :dependent => :destroy
base.send :has_many, :sections_with_questions, :include => :questions, :class_name => "SurveySection", :order => "#{SurveySection.quoted_table_name}.display_order"
base.instance_eval {has_many :sections, ->{order "#{SurveySection.quoted_table_name}.display_order"}, :class_name => "SurveySection", :dependent => :destroy}
base.instance_eval {has_many :sections_with_questions, ->{includes(:questions).order("#{SurveySection.quoted_table_name}.display_order")}, :class_name => "SurveySection"}
base.send :has_many, :response_sets
base.send :has_many, :translations, :class_name => "SurveyTranslation"

Expand Down

0 comments on commit 33a9f62

Please sign in to comment.