# Count a occurence of given attribute

**URL:** <https://www.ruby-forum.com/t/count-a-occurence-of-given-attribute/156640>\
**Category:** Rails\
**Created:** [December 31, 2008, 8:12am UTC](https://www.ruby-forum.com/t/count-a-occurence-of-given-attribute/156640 "2008-12-31T08:12:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ishara\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e68b1a/32.png) [@Ishara\_G](https://www.ruby-forum.com/u/Ishara_G)\
**Post date:** [December 31, 2008, 8:12am UTC](https://www.ruby-forum.com/t/count-a-occurence-of-given-attribute/156640/1 "2008-12-31T08:12:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ishara\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e68b1a/32.png) [@Ishara\_G](https://www.ruby-forum.com/u/Ishara_G)\
**Post date:** [December 31, 2008, 9:25am UTC](https://www.ruby-forum.com/t/count-a-occurence-of-given-attribute/156640/2 "2008-12-31T09:25:20Z")

</div>

Just do:

agent.confirm\_clients.count([“confirm = ?”, true])

* * *

Ryan B.  
Freelancer

> **[frozenplague.net](http://frozenplague.net)**
>
> This domain may be for sale!
