Forum: Ruby on Rails count a occurence of given attribute

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dcf093a36c8a7e286dbefe10454813e1?d=identicon&s=25 Ishara Gunathilake (Guest)
on 2008-12-31 08:12
(Received via mailing list)
hi,,
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

agents
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 table.as an example

if confirm_clients table agent_id=agent1 has 4 boolean true rows so i
want
to save 4 in
the agents table rank column,corresponding agent1s row.plz can anyone
help
me to
solve this problem
9a2a53db8e9b4476038c94a64b32833f?d=identicon&s=25 Ryan Bigg (ryan-bigg)
on 2008-12-31 09:25
(Received via mailing list)
Just do:

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

-----
Ryan Bigg
Freelancer
http://frozenplague.net
This topic is locked and can not be replied to.