我有@bunch
个模型作为数组返回
每个模型都有属性-commentable_id
和commentable_type
(多态关联)
我想按注释对模型进行分组,但如果我这样做了
@bunch.group_by(&:commentable)
它还从数据库中获取不需要的注释.
我可以做@bunch.group_by(&:commentable_id)
,但这会造成一些混乱,因为可能有几种类型的可注释模型
有go group_by
commentable_id
和commentable_type
的路吗?