I am new to ROR and Postgre and I have problems with this.
I have a Work_hour and Merchant Model where the seller has_many working_hours and working_hour are owned by Merchant. A merchant can have two or more business days in one day.
My opinion:
<% @merchant.working_hours.order(:day).group_by(&:day).each do |dia, whs| %> <%= t(:"date.abbr_day_names")[dia.to_i] %> : <% whs.each do |wh| %> <li> <%= wh.oppening_hour.to_formatted_s(:time) %> - <%= wh.close_hour.to_formatted_s(:time) %> </li> <% end %> <% end %>
When I show the data received in order of time (note that the opening hour is unordered):
Mon: 17:00-20:00 10:00-13:00 Tue: 18:00-21:00 10:00-13:00
I want to group the day of the week and first order the day of the week , and the second - the opening hour :
Mon: 10:00-13:00 17:00-20:00 Tue: 10:00-13:00 18:00-21:00
But, as you can see, I am currently using the ruby ββlayer for this, which leads to performance problems. How to achieve this with a database tier?
source share