我的一个模型中有这个 named_scope:
named_scope :latest_100,
:from => '(select * from videos order by videos.created_at desc limit 0, 100) as videos'
它的目的是创建一个包含最后 100 个视频的池(将该结果作为“视频”返回,以便其他范围在该数据集上运行),然后我可以在此之后链接范围并从该结果池中过滤记录。
# video.rb
named_scope :most_popular, :order => 'popularity'
named_scope :take_5, :limit => 5
# video_controller.rb
# it gets the latest 100 videos, then sorts those by popularity, and takes the top 5.
@videos = Video.latest_100.most_popular.take_5
是否有与 Arel 相同的声明?