Created
December 27, 2016 16:19
-
-
Save StaverDmitry/2f9cfe7068cf208d4a0baa802634bcf5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sorted_pax_list | |
ship_priority = ['Standard', 'Ensuite', 'Premier', 'Premier Plus'] | |
name_condition = "CASE WHEN first_name <> '' THEN 1 ELSE 0 END DESC" | |
deck_condition = "CASE deck WHEN 'Above Deck' THEN 1 ELSE 0 END DESC" | |
ship_condition = "CASE ship_type " | |
ship_priority.each_with_index { |ship, i| ship_condition += "WHEN '#{ship}' then #{i} "} | |
ship_condition += "END DESC" | |
partners = Partner.where(id: enquiry.partners.pluck(:id)) # Somehow ordering does not work without this | |
partners.order("#{name_condition}, #{ship_condition}, #{deck_condition}") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Таск: сортировка списка пассажиров( они же pax, они же partners ).
В приоритете наличие имени, во вторую очередь тип корабля, в последнюю очередь верхняя или нижняя палуба.