Rails case insensitive group_by?

ok so i have this call

location.requests.group_by(&:song)

location

>> location = Location.find 4
=> #<Location id: 4, venue: "Rod Laver Arena at Melbourne Park - Melbourne Vic, ...", 
showdate: "2010-11-20", created_at: "2010-10-28 01:20:42", updated_at: 
"2010-10-28 01:20:42", band_id: nil, artist_name: "Metallica">


location.requests.group_by(&:song)

this call returns two records, “One” and “One”, because they are stored in db this way .... any idea on how to redo group_by just to return one record with

I am using sqlite

+3
source share
1 answer

Group_by can also accept a block of code. Therefore, instead of:

location.requests.group_by(&:song)

do:

location.requests.group_by{|i| i.song.downcase}

See here for relevant documentation.

+10
source

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


All Articles