mammoth-guitar-49791
08/13/2023, 5:12 PMruby
self.resolve_query_scope = ->(model_class:) do
model_class.trending_1.from_active_channels
end
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
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]]
lemon-wall-20836
08/13/2023, 5:20 PMmammoth-guitar-49791
08/13/2023, 5:22 PMmammoth-guitar-49791
08/13/2023, 8:31 PMlemon-wall-20836
08/14/2023, 8:51 AM