I have the following working has_many with a proc to capture a parameter for context:
has_many :subclass_point_analytics, :conditions => proc {"assessment_id = #{self.send(:assessment_id)}" }, :foreign_key => 'gid', :dependent => :destroy
I am using Rails 4 and it is (rightfully) complaining about use of :conditions. After 30 minutes and lots of tries I cannot figure out how to convert :conditions to -> { where ... } format. I would appreciate someone with knowledge of proc syntax to help me get that correct.
Just do this:
has_many :subclass_point_analytics, -> (object) { where("assessment_id = ?", object.assessment_id) }, :foreign_key => 'gid', :dependent => :destroy
object is your actual instance. Also, watch out: the callable has to be the first thing (:conditions tend to be at the end)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With