-
-
Notifications
You must be signed in to change notification settings - Fork 909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Has many through association: undefined method `klass' for nil:NilClass #611
Comments
Yeah, can you re-run the tests with the |
|
You're saying that Ideally, we should probably have a check to ensure that your |
I added the Feel free to close the issue, unless you want to keep it open for adding a different error message. |
Sounds good, glad I could help. |
I have this error with code like this one: class Subject < ActiveRecord::Base
has_one :subject_photo_assignment
has_many :photos, through: :subject_photo_assignments
end |
@1v You have a |
@mcmire it's working with "s" too, but tests failing. |
@1v Okay. Have you tried: class Subject < ActiveRecord::Base
has_one :subject_photo_assignment
has_many :photos, through: :subject_photo_assignment # note that this is singular, not plural
end |
@mcmire yeah that's how I do right now. But Rails accepts plural too. It took me time to figure out because error message not informative. |
@1v Okay, fair enough. I'll re-open this issue. |
I also have this error with this "setup": module Hanuman
class Observation < ActiveRecord::Base
belongs_to :survey, touch: true
end
end Hanuman::Observation.class_eval do
has_one :user, through: :survey
end module Hanuman
RSpec.describe ObservationAnswer, type: :model do
it { is_expected.to have_one(:user).through(:survey) }
end
end
|
I can verify that the reported issue has been fixed in the version Before: Failure/Error: it { should have_many(:words).through(:pag) }
NoMethodError:
undefined method `class_name' for nil:NilClass
Did you mean? class_eval After: Failure/Error: it { should have_many(:words).through(:pag) }
Expected Book to have a has_many association called words through pages (Could not find the source association(s) "word" or :words in model Page. Try 'has_many :words, :through => :pages, :source => <name>'. Is it one of book?) Error text differs as i'm using rails |
Thanks! Closing. |
Hi!
I have an Subject model which should have many Photos through SubjectPhotoAssignments. When I test this, I get
undefined method 'klass' for nil:NilClass
. Here is my setup:Here is the failing test:
What am I doing wrong? Any help is greatly appreciated. Let me know if more context would be helpful.
I'm using v2.7.0
The text was updated successfully, but these errors were encountered: