I have three activerecord models:
the "A"
class User < ApplicationRecord
has_many :user_violation, class_name: "UserViolation", inverse_of: :user
has_many :violations, through: :user_violation, class_name: "Violation"
end
the middle:
class UserViolation < ApplicationRecord
belongs_to :user, class_name: "User", foreign_key: :user_id
belongs_to :violation, class_name: "Violation", foreign_key: :violation_id
end
the B:
class Violation < ApplicationRecord
end
I need to find all users who have AT LEAST one violation with column: fatal
set to true.
Im kinda stuck here and this is not working:
User.joins(:violations).where('violations.fatal = true')