0

我有以下表ORDERBY在Rails的關聯

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遞減

我試圖基於在

創建如何根據項目緩存created_at訂購這些書籤的項目活動寫在書籤模型範圍爲

scope :ordered, :joins => :activity, :order => "activities.created_at DESC" 

上述種種

建議請

回答

1

也許這會工作:

scope :ordered, :include => [{ :activity => :item_cache }], :order => "item_caches.created_at desc" 

以上代碼假定:

bookmark.rb 
    belongs_to :activity 

activity.rb 
    belongs_to :item_cache