I'm facing a strange issue with an ActiveRecord association in my Ruby on Rails project. When I try to access the laps association method from my User model, I get a peculiar error.
Error:
ArgumentError: The Lap model class for the User#laps association is not an ActiveRecord::Base subclass.
I've double-checked, and Lap is definitely a subclass of ActiveRecord::Base. I'm using Rails 7.1.3 and Ruby 3.2.2.
Here's the code for my User model:
class User < ApplicationRecord
has_many :laps
end
And here's the code for my Lap model:
class Lap < ApplicationRecord
belongs_to :user
end
I can't figure out why I'm getting this error. Has anyone else encountered a similar issue or have any ideas on how to resolve it?
I use
User.reflect_on_association(:laps).klass
what create an error
but with the relation quiz has_many :laps and Quiz.reflect_on_association(:laps).klass
There is no errors in the 2nd case so I didn't understand why to similar code have different résult.