我有以下表格
One is Bookmarking Table has (activity_id as foreign key)
Table 2 - Activity has(item_id as foreign key..)
Table 3 - ItemCache has (id,item_id,item_type, created_at...)
Table 4 - Blog has(id,title,user_id,created_at...)
Table 5 - Tweet has (id,title,user_id,created_at..)
项目表包含实际项目博客,保存推文 当此项目被加入书签时,活动将被保存
现在我正在尝试获取用户的所有已添加书签的项目 我使用
获取current_user.bookmarks
现在我想根据created_at desc
项目订购这些带书签的商品我尝试在书签模型中编写范围
scope :ordered, :joins => :activity, :order => "activities.created_at DESC"
以上排序基于
创建的活动如何根据项目缓存created_at
订购这些已添加书签的项目建议
答案 0 :(得分:1)
也许这会奏效:
scope :ordered, :include => [{ :activity => :item_cache }], :order => "item_caches.created_at desc"
以上代码假定:
bookmark.rb
belongs_to :activity
activity.rb
belongs_to :item_cache