class User
has_many :messages do
def by_type(type, options={})
conditions = [ 'type = ?', type ]
if options[:count_only]
count(:conditions => conditions)
else
find(:all, :conditions => conditions)
end
end
end
end
refs:
http://refactormycode.com/codes/209-rails-has_many-count
--
tommy xiao
E-mail: xiaods(AT)gmail.com
没有评论:
发表评论