Forum: Ruby on Rails count a occurence of given attribute

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ishara G. (Guest)
on 2008-12-31 09:12
(Received via mailing list)
i have a two tables named "agents" and "confirm_clients"
in confirm_clients columns
t.column :client_id, :string
t.column: agent_id, :string
t.column:confirm, :boolean

t.column :agent_id, :string
t.column :rank, :integer

i want to count the occurence of each agent_id ,which the
confirm boolean is "true" and i want to save that count number
in the rank column of agents an example

if confirm_clients table agent_id=agent1 has 4 boolean true rows so i
to save 4 in
the agents table rank column,corresponding agent1s row.plz can anyone
me to
solve this problem
Ryan B. (Guest)
on 2008-12-31 10:25
(Received via mailing list)
Just do:

agent.confirm_clients.count(["confirm = ?", true])

Ryan B.
This topic is locked and can not be replied to.