Using Rails 6 rc1, I'm doing a query on a model called 'Job'.

Job Model (job.rb):

has_rich_text :description
belongs_to :company, dependent: :destroy, required: false

def self.search(query)  
  joins(:company, :description)
  .where.not(has_ended: true)
  .where("jobs.title ILIKE ?", query)
  .where("jobs.description ILIKE ?", query)
  .where("companies.name ~* ?", "^#{query}") # https://www.postgresql.org/docs/8.3/functions-matching.html
end

That's exactly what I have. So far my issue is with the inclusion of has_rich_text. The error, when replicated in the rails console Job.joins(:description):

ActiveRecord::AssociationNotFoundError (Association named 'description' was not found on Job; perhaps you misspelled it?

When searching "hight and low", I could not find any documentation on this level of query. I havent tried scope mentioned here.

1 Answers

0
Sylar On

It turns out you can! I've posted the menthod on the Rails Github page I've used but need to know if there is a better way.