Ho il seguente codice associazioni:chiave sconosciuta in associazione Rails
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
Si genera un errore:
Unknown key: :conditions. Valid keys are: :class_name, :class, :foreign_key, :validate, :autosave, :table_name, :before_add, :after_add, :before_remove, :after_remove, :extend, :primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache
Ho provato a cambiare la prima linea in:
has_many :rates_without_dimension, :as => :rateable, :class_name => "Rate", :dependent => :destroy,-> { where(:dimension => nil) }
Ma ha anche sollevato un errore, puoi indicarmi cosa c'è di sbagliato in esso?
Modificato la domanda per includere il codice sorgente da un sito esterno. Da [SO help] (http://stackoverflow.com/help/how-to-ask): "Se è possibile creare un esempio dal vivo del problema a cui è possibile collegarsi (ad esempio, su http: // sqlfiddle.com/ o http://jsbin.com/), quindi includi anche il codice nella domanda stessa. Non tutti possono accedere a siti esterni e i collegamenti potrebbero interrompersi nel tempo ". – Amadan
Grazie per la modifica e la citazione :) –
Qual è stato l'errore utilizzando la notazione ->? – JTG