Distinct values
# avo-2
m
Does avo add a distinct by default to scopes?
Copy code
ruby
  self.resolve_query_scope = ->(model_class:) do
    model_class.trending_1.from_active_channels
  end
Copy code
ruby
class Video << ApplicationRecord
  scope :from_active_channels, -> { joins(:channel).where(channels: {active: true}) }
  scope :trending_1, -> { joins(:video_score).order("video_score.score_1 DESC") }
end
this scope above produces
Copy code
SELECT DISTINCT video_score.score_1 AS alias_0, videos.created_at AS alias_1, "videos"."id" FROM "videos" INNER JOIN "video_scores" "video_score" ON "video_score"."video_id" = "videos"."id" LEFT OUTER JOIN "channels" ON "channels"."id" = "videos"."channel_id" LEFT OUTER JOIN "songs" ON "songs"."id" = "videos"."song_id" LEFT OUTER JOIN "events" ON "events"."id" = "videos"."event_id" LEFT OUTER JOIN "dancer_videos" ON "dancer_videos"."video_id" = "videos"."id" LEFT OUTER JOIN "dancers" ON "dancers"."id" = "dancer_videos"."dancer_id" LEFT OUTER JOIN "active_storage_attachments" ON "active_storage_attachments"."record_type" = $1 AND "active_storage_attachments"."name" = $2 AND "active_storage_attachments"."record_id" = "videos"."id" LEFT OUTER JOIN "active_storage_blobs" ON "active_storage_blobs"."id" = "active_storage_attachments"."blob_id" ORDER BY video_score.score_1 DESC, videos.created_at desc LIMIT $3 OFFSET $4  [["record_type", "Video"], ["name", "thumbnail"], ["LIMIT", 24], ["OFFSET", 0]]
l
No, it doesn’t
@lemon-wall-20836 You were write I can into a weird quirk where includes was doing the wrong thing and also throwing in a distinct when it had no reason to do so. explicitely calling preload seemed to work.
l
nice! GJ of rfinding that!