-
I check the document, but never found how to write where like this: where universities.name &@~ 'foo' I done my job use class Universities::Index < BrowserAction
get "/universities" do
q = params.get?(:q)
is_985 = params.get?(:is_985)
is_211 = params.get?(:is_211)
is_good = params.get?(:is_good)
builder = Avram::QueryBuilder.new(table: :universities)
unless q.blank?
builder = builder.where(Avram::Where::Raw.new("(universities.name &@~ ?", q))
builder = builder.or do |or|
or.where(Avram::Where::Raw.new("universities.description &@~ ?)", q))
end
end
results = UniversityQuery.new
results.query = builder
unless is_985.blank?
results = results.is_985(true)
end
pp! results.to_sql
pages, universities = paginate(results.id.desc_order, per_page: 50)
html IndexPage, universities: universities, pages: pages
end
end It works! the above output of
Can i do same thing just use Thanks. |
Beta Was this translation helpful? Give feedback.
Answered by
jwoertink
May 1, 2024
Replies: 1 comment 2 replies
-
You need to use a raw where query for this. query = UniversityQuery.new
if q = params.get?(:q).presence
query = query.where("name &@~ ?", q).or(&.where("description &@~ ?", q))
end
pp! query.to_prepared_sql I haven't seen the |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
zw963
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to use a raw where query for this.
I haven't seen the
&@~
query before. What do you call this?