0
我有一个Library
,一个Library
有很多Book
s。Rails根据关联计数的默认范围排序
class Library < ActiveRecord::Base
has_many :book_collectings
has_many :books, through: :book_collectings
如何使用default_scope
使Library.all
是基于图书Library
具有数量排序? (还是有不同的做法?)
同意default_scope几乎总是最终变得邪恶。 – 99miles
设置counter_cache并让它工作。万分感谢 :) – wyclin