I'm a React, Javascript & Rails full-stack Software Engineer. I have been working remotely for the past two years in a remote village. Before joining as a Software Engineer I founded kwiq - a hyperlocal delivery startup to deliver things in remote villages.
1 minute read
ActiveRecord::Relation#order is used to specify the order in which records should be retrieved from the database.
Recently in Rails 7.2 ActiveRecord::Relation#orderadded support
for hash values.
ActiveRecord::Relation can take a hash where keys are table name, value is a hash of key (column name)
and value (order direction). For example:
Let’s see some examples with the Client
and
Project models.
Before
Before 7.2,
we were able to order records with the following syntax: