简体   繁体   English

在Rails中不区分大小写的group_by?

[英]Case insensitive group_by in Rails?

ok so i have this call 好的,我有这个电话

location.requests.group_by(&:song)

location is 位置是

>> 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 is returning two records "One" and "one" because they are saved that way in the db....any idea on how to redo the group_by to only return one record with both 这个调用返回两个记录“One”和“one”,因为它们以这种方式保存在db中....任何想法如何重做group_by只返回一个记录

I am using sqlite 我正在使用sqlite

Group_by can also take a code block. Group_by也可以采用代码块。 So instead of: 所以代替:

location.requests.group_by(&:song)

Do: 做:

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

See here for pertinent documentation. 请参阅此处了解相关文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM