I'm trying to get show a list of polymorphic relations without having any duplicates.
I have a StoreViews table with a polymorphic field called viewable (so there's a viewable_id and viewable_type column in my table). Now I want to display views with each polymorphic relation showing up just once, without duplicates.
@views = StoreView.
.distinct(:viewable_id)
.distinct(:viewable_type)
.order("created_at DESC")
.limit(10)
So if there's two records in StoreViews, both with the same viewable relation, @views should only return the most recent one. However, this is not the case.