【发布时间】:2019-05-11 07:12:05
【问题描述】:
使用 Rails 6 rc1,我正在对名为“Job”的模型进行查询。
工作模型(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
这正是我所拥有的。到目前为止,我的问题是包含has_rich_text。在 rails 控制台Job.joins(:description) 中复制时出现的错误:
ActiveRecord::AssociationNotFoundError(在 Job 上找不到名为“description”的关联;也许你拼错了?
在搜索“hight and low”时,我找不到有关此级别查询的任何文档。我没试过scopementioned here。
【问题讨论】:
-
如果
description是一个你不能加入的属性。您只能加入表格。从joins(:company, :description)中删除:description。 -
嗨。正确的。但是....如何通过查询访问操作文本?
标签: ruby-on-rails ruby-on-rails-6