First, you'll need to incorporate the extension:
class ApplicationRecord < ActiveRecord::Base
extend QueryExtensions
end
Now, you can use it like this:
class Author < ApplicationRecord
end
Author.where_has { age.eq(29).or(age.gt(40)) }
# SELECT "authors".* FROM "authors" WHERE ("authors"."age" = 29 OR "authors"."age" > 40)
Author.joins(:posts).where_has { Post[:title].matches("Breaking News:%") }
# SELECT "authors".* FROM "authors" INNER JOIN "posts" ON "posts"."author_id" = "authors"."id" WHERE "posts"."title" LIKE 'Breaking News:%'
In the example above, age
and Post[:title]
are instances of Arel::Attributes::Attribute
.