Counting and grouping at the same time

后端 未结 4 2006
轻奢々
轻奢々 2020-12-08 01:39

I have a Mail model with the following schema:

t.string   \"mail\"
t.integer  \"country\"
t.boolean  \"validated\"
t.datetime \"created_at\"
t.d         


        
4条回答
  •  猫巷女王i
    2020-12-08 02:04

    Try:

    Mail.count(:group => 'country', :conditions => ['validated = ?', 't'])

    I'm not sure count accepts :limit though.

    EDIT:

    I think this is more readable:

    Mail.count(:group => :country, :conditions => {:validated => true})

提交回复
热议问题