Given the following Ruby-on-Rails code (1.8.6, 2.3.5):
class MyClass < ActiveRecord::Base
has_many :modifiers,
:conditions => ["affects_class = ?", self.name],
:foreign_key => :affects_id
end
What I'm trying to do is to automatically set the affects_class
column to 'MyClass'
. In other words:
myInstance = MyClass.find(:first)
modifier = Modifier.new
modifier.affects_class = self.name # Don't want to have to do this
myInstance.modifiers << modifier
I don't want to have to set modifier.affects_class
. After all, I don't have to set modifier.affects_id
; that's set automatically by the has_many
relation. Is there some option I can set on has_many
? Or am I stuck having to set it each time?