muratguzel / letsrate

The best way to add rating capabilities to your rails application and your activerecord models.
http://letsrate.herokuapp.com
198 stars 234 forks source link

deprecation warning when running rails console for associations #48

Closed aravindgd closed 10 years ago

aravindgd commented 10 years ago

I am using the letsrate gem in Rails 4 application. I have added the gem into my lib file and changed it a bit for making it to work with Rails 4. Now I am getting a deprecated warning like this:

DEPRECATION WARNING: The following options in your Performer.has_many :rates_without_dimension declaration are deprecated: :conditions. Please use a scope block instead. For example, the following:

has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'

should be rewritten as the following:

has_many :spam_comments, -> { where spam: true }, class_name: 'Comment' . (called from letsrate_rateable at /home/aravind/Documents/dev/gw-c4u/lib/letsrate/lib/letsrate/model.rb:76) DEPRECATION WARNING: The following options in your Performer.has_one :rate_average_without_dimension declaration are deprecated: :conditions. Please use a scope block instead. For example, the following:

has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'

should be rewritten as the following:

has_many :spam_comments, -> { where spam: true }, class_name: 'Comment' . (called from letsrate_rateable at /home/aravind/Documents/dev/gw-c4u/lib/letsrate/lib/letsrate/model.rb:79) DEPRECATION WARNING: The following options in your Performer.has_many :performance_rates declaration are deprecated: :conditions. Please use a scope block instead. For example, the following:

has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'

should be rewritten as the following:

has_many :spam_comments, -> { where spam: true }, class_name: 'Comment' . (called from block in letsrate_rateable at /home/aravind/Documents/dev/gw-c4u/lib/letsrate/lib/letsrate/model.rb:84) DEPRECATION WARNING: The following options in your Performer.has_one :performance_average declaration are deprecated: :conditions. Please use a scope block instead. For example, the following:

has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'

should be rewritten as the following:

has_many :spam_comments, -> { where spam: true }, class_name: 'Comment' . (called from block in letsrate_rateable at /home/aravind/Documents/dev/gw-c4u/lib/letsrate/lib/letsrate/model.rb:91)

The part of the file which generates such an error is this:

module ClassMethods

def letsrate_rater
  has_many :ratings_given, :class_name => "Rate", :foreign_key => :rater_id       
end    

def letsrate_rateable(*dimensions)
  has_many :rates_without_dimension, :as => :rateable, :class_name => "Rate", :dependent => :destroy, :conditions => {:dimension => nil}
  has_many :raters_without_dimension, :through => :rates_without_dimension, :source => :rater  

  has_one :rate_average_without_dimension, :as => :cacheable, :class_name => "RatingCache", 
      :dependent => :destroy, :conditions => {:dimension => nil}

  dimensions.each do |dimension|        
    has_many :"#{dimension}_rates", :dependent => :destroy, 
                               :conditions => {:dimension => dimension.to_s}, 
                               :class_name => "Rate", 
                               :as => :rateable

    has_many :"#{dimension}_raters", :through => "#{dimension}_rates", :source => :rater         

    has_one :"#{dimension}_average", :as => :cacheable, :class_name => "RatingCache", 
                                :dependent => :destroy, :conditions => {:dimension => dimension.to_s}
  end                                                    
end

I have tried bringing the :dependent=>:destroy to the last part of the line and changing conditions => {:dimension => dimension.to_s} to -> {:dimension => dimension.to_s}. It only throws errors. What am I doing wrong?

muratguzel commented 10 years ago

Hi .. For a long time, I have not enough time to mange this gem. But nowadays I'm available. You can check this issue 2-3 days later. Thanks ...

muratguzel commented 10 years ago

Fixed and new version 1.0.9 is released. Thanks...