# Associations counting

**URL:** <https://www.ruby-forum.com/t/associations-counting/122384>\
**Category:** Rails\
**Created:** [December 7, 2007, 5:36am UTC](https://www.ruby-forum.com/t/associations-counting/122384 "2007-12-07T05:36:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ranieri\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/43a26b/32.png) [@Ranieri\_T](https://www.ruby-forum.com/u/Ranieri_T)\
**Post date:** [December 7, 2007, 5:36am UTC](https://www.ruby-forum.com/t/associations-counting/122384/1 "2007-12-07T05:36:27Z")

</div>

Hi,  
I’m using the models, User, Item, and Add.  
Add belongs\_to User (with counter\_cache enabled)  
Add belongs\_to Item (also, with counter\_cache enabled)  
User has\_many adds, and has\_many items through adds  
Item has\_many adds, and has\_many users through adds

When I go to save a new Item, I want to create a new Add for this, with  
the proper (loged in) User:

@item.adds.create :user =\> @current\_user

In the view, the number of items is displayed currectly, but in the  
database it is shown as 0, if I looking at the items table; at the same  
time the table users show: adds\_count = 1, or the currect number of  
adds.

Why? How can I fix it?  
Ranieri T.

* * *

Abra sua conta no Yahoo! Mail, o Ãºnico sem limite de espaÃ§o para  
armazenamento!
