Shane Sizer
2006-Jul-31 04:35 UTC
[Rails] Issues with has_many, belongs_to and dependency settings
I have 2 models SmsAddress & OutboundSmsAtom
SmsAddress {
has_many :other_objects, :dependency => :nullify
}
OutboundSmsAtom {
#note this object also "belongs_to" other objects if that matters
belongs_to :this_object
}
Whenever I try to destroy an object of type ThisObject, which at the time
has 0 "children" OtherObjects I get the following type of error
message
>> address.destroy
NameError: uninitialized constant OuboundSmsAtom
from
/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependenc
ies.rb:100:in `const_missing''
from
/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependenc
ies.rb:131:in `const_missing''
from
/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependenc
ies.rb:133:in `const_missing''
from (eval):1:in `configure_dependency_for_has_many''
from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/callbacks.
rb:337:in `callback''
from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/callbacks.
rb:330:in `callback''
from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/callbacks.
rb:320:in `destroy_without_transactions''
from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/transactio
ns.rb:122:in `destroy''
from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/connection
_adapters/abstract/database_statements.rb:51:in `transaction''
from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/transactio
ns.rb:91:in `transaction''
from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/transactio
ns.rb:118:in `transaction''
from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/transactio
ns.rb:122:in `destroy''
from (irb):18>> exit
If I turn of the :dependent property it then works fine. I''m sort of
stumped. Thanks in advance if anyone has a fix, or even better a fix for
what must be some sort of conceptual mistake I''m making.
Cheers - Shane
