Skip to content

Is there a way to use FooQuery write self-defined where clause? e.g. where universities.name &@~ 'foo' #1882

Answered by jwoertink
zw963 asked this question in Q&A
Discussion options

You must be logged in to vote

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 &@~ query before. What do you call this?

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@zw963
Comment options

@jwoertink
Comment options

Answer selected by zw963
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants