Gary Weaver
2012-Nov-19 20:08 UTC
has_one :through NoMethodError: undefined method `klass'' for nil:NilClass when doing class_name on reflection
Not sure if this is expected or not. Only happened with a has_one :through
I had setup. (Workaround is just to remove it and go through the
association manually vs has_one ..., through: .)
Not a big deal if no one has time to look at it, as it''s not a big
enough
deal to look into a fix on our side.
In Rails (3.2.9) console if I do:
MyModel.reflections.each {|name,reflection| reflection.class_name }
it raises:
NoMethodError: undefined method `klass'' for nil:NilClass
from
/path/to/rvm/gems/ruby-1.9.3-p194@my_project/gems/activerecord-3.2.9/lib/active_record/reflection.rb:385:in
`block in source_reflection''
from
/path/to/rvm/gems/ruby-1.9.3-p194@my_project/gems/activerecord-3.2.9/lib/active_record/reflection.rb:385:in
`collect''
from
/path/to/rvm/gems/ruby-1.9.3-p194@my_project/gems/activerecord-3.2.9/lib/active_record/reflection.rb:385:in
`source_reflection''
from
/path/to/rvm/gems/ruby-1.9.3-p194@my_project/gems/activerecord-3.2.9/lib/active_record/reflection.rb:530:in
`derive_class_name''
from
/path/to/rvm/gems/ruby-1.9.3-p194@my_project/gems/activerecord-3.2.9/lib/active_record/reflection.rb:127:in
`class_name''
from (irb):6:in `block in irb_binding''
from (irb):6:in `each''
from (irb):6
from
/path/to/rvm/gems/ruby-1.9.3-p194@my_project/gems/railties-3.2.9/lib/rails/commands/console.rb:47:in
`start''
from
/path/to/rvm/gems/ruby-1.9.3-p194@my_project/gems/railties-3.2.9/lib/rails/commands/console.rb:8:in
`start''
from
/path/to/rvm/gems/ruby-1.9.3-p194@my_project/gems/railties-3.2.9/lib/rails/commands.rb:41:in
`<top (required)>''
from script/rails:6:in `require''
from script/rails:6:in `<main>''
Simplified versions of models:
class MyModel < ActiveRecord::Base
has_one :bar, through: :foo
end
class Foo < ActiveRecord::Base
self.table_name = :somenonstandardnamehere
self.primary_key = :nonstandardish_id
# ...
has_one :bar, foreign_key: ''anothernonstandard_id''
end
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-core/-/sRQEFXU5kEIJ.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-core+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.
Seemingly Similar Threads
- active_model_serializers, more than one level deep of associations, specifying serializers per association
- #8498 postgres_adapter fix for disable_referential_integrity
- unexpected return (LocalJumpError) only when executing this code within autoloaded classes?
- Error Bundler
- after_fork - ActiveRecord::AdapterNotSpecified
