s.name = 'activerecord' .... s.add_dependency 'activesupport', version s.add_dependency 'activemodel', version s.add_dependency 'arel', '7.0.0.alpha' end
search_term where(table[:cuisine].matches_any(['%indian%', "%#{search_term}%"])) end end # SELECT restaurants.* FROM restaurants # WHERE ((restaurants.cuisine ILIKE '%indian%' OR # restaurants.cuisine ILIKE '%india%'))
search_term where(table[:cuisine].matches_any(['%indian%',"%#{search_term}%"])) end end # SELECT restaurants.* FROM restaurants # WHERE ((restaurants.cuisine ILIKE '%indian%' OR restaurants.cuisine # ILIKE '%india%')) where(a: something) where(“a like ?”, something) where(AST)
search_term where(table[:cuisine].matches_any(['%indian%',"%#{search_term}%"])) end end # SELECT restaurants.* FROM restaurants # WHERE ((restaurants.cuisine LIKE '%indian%' OR restaurants.cuisine # LIKE '%india%')) Same query on MySQL database
self.food_search_not search_term where("cuisine_type NOT ILIKE '%nonveg%'") end end # SELECT restaurants.* FROM restaurants WHERE # (restaurants.cuisine_type NOT ILIKE '%nonveg%')
self.food_search_not search_term where(table[:cuisine_type].does_not_match('%nonveg%')) end end # SELECT restaurants.* FROM restaurants WHERE # (restaurants.cuisine_type NOT ILIKE '%nonveg%')
with reviews having rating more than 3 Location.table.join(Review.table) .on(Location.table[:id].eq(Review.table[:location_id]) .and(Review.having_rating_more_than(3))) .project(Arel.star) # All locations with bookings Location.joins(:bookings)
ON locations.id = reviews.location_id # AND reviews.rating > 3 # UNION # SELECT locations.* FROM locations INNER JOIN bookings # ON bookings.location_id = locations.id
self.order_criteria_raw "coalesce('completed_at', 'created_at')" end end Task.order(Task.order_criteria_raw) #=> SELECT "tasks".* FROM "tasks" ORDER BY coalesce('completed_at', 'created_at')
self.order_criteria Arel::Nodes::NamedFunction.new('coalesce', ['completed_at', 'created_at']) end end Task.order(Task.order_criteria_raw) #=> SELECT "tasks".* FROM "tasks" ORDER BY coalesce('completed_at', 'created_at')