How to write scope with belongs_to object?
I would do something like this (from http://guides.rubyonrails.org/active_record_querying.html)
class Job
scope :accepted_with_active_company, ->() {
joins(:company).where('companies.state' => "accepted")
}
end