How to create an area for ordering a city name?

I have two models / tables: services and city

Service Model:

belongs_to :origin_city, class_name: 'City' belongs_to :destiny_city, class_name: 'City' 

How to create an area for ordering a city name?

I am trying something like this:

 scope :by_city_name, -> { joins(:city).order("cities.name asc") } 

But I just want to order the city of origin of the service in one area. And the service of the city of fate in another area.

0
source share
1 answer

So, you should only join origin_city :

 scope :by_origin_city_name, -> { joins(:origin_city).order('cities.name asc') } 
0
source

Source: https://habr.com/ru/post/985355/


All Articles