我有一個實體報告集團通過和合並由
Report(id: integer, pos: integer, project_id: integer, key_id: integer, created_at: datetime)
因爲有與相同值的記錄,但只有pos
不同,我想通過key_id
和merge
的pos
列組他們。這樣做的
方式一:
Report.group(:key_id, :pos).select(:key_id, :pos) OR .size
和環拋出的每一個,如果有上KEY_ID匹配追加新pos
預期輸出:
1. {"key" => "key_id", "pos" => "pos"}
2. {"key" => "key_id", "pos" => "pos1"}
Result => {"key" => "key_id", "pos" => "pos, pos1"}
有這樣做的更好方法?