Skip to content
Carlos edited this page Aug 19, 2019 · 1 revision

Additional Arel features. In order to provide correct and smooth statements for the new features provided by this GEM, a bunch of Arel extensions where provided.

Inflix operators

PostgreSQL allows a bunch of custom operators while working with Arrays, Ranges, and Hashes.

These are the ones implemented and can be used with Arel nodes and attributes:

  • .overlaps => &&
  • .contains => @>
  • .contained_by => <@
  • .has_key => ?
  • .has_all_keys => ?&
  • .has_any_keys => ?|
  • .strictly_left => <<
  • .strictly_right => >>
  • .doesnt_right_extend => &<
  • .doesnt_left_extend => &>
  • .adjacent_to => -|-

Cast values

One of the things that allowed array associations and the period operations is being able to cast things from one type to another right on Arel. This means that time columns can be casted into dates and have all the capabilities of a normal Arel node.

If you are used to Arel, to cast something it's pretty simple:

Event.arel_table[:created_at].cast(:date)

which will produce

"events"."created_at"::date
Clone this wiki locally