change ".all.uniq" to ".uniq_by(&:id)"