# Contents of a has\_many collection

**URL:** <https://www.ruby-forum.com/t/contents-of-a-has-many-collection/106125>\
**Category:** Rails\
**Created:** [June 6, 2007, 5:51pm UTC](https://www.ruby-forum.com/t/contents-of-a-has-many-collection/106125 "2007-06-06T17:51:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![halfgaar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ea666f/32.png) [@halfgaar](https://www.ruby-forum.com/u/halfgaar)\
**Post date:** [June 6, 2007, 5:51pm UTC](https://www.ruby-forum.com/t/contents-of-a-has-many-collection/106125/1 "2007-06-06T17:51:57Z")

</div>

Hi,

I need some help understanding when fields of a Rails model are  
updated. In this case, it’s about the fields of a has\_many collection.

I have a hypothetical model beehive, which has\_many(:bees). In the  
controller, I do (example is abstracted):

bees = Array.new

params[“bees”].each\_value do |bee\_attributes|  
bee = beehive.bees.build(bee\_attributes)  
bees.push(bee)  
end

beehive.bees = bees

This all works fine, except when I try to access the bees of beehive  
again, which I need for validations. I made a validate method in  
beehive which runs by all the bees to check some stuff (what is not  
important). The problem is, that the bees collection I have access to  
in the validate method still contains the values from the DB, which  
were loaded when this model was loaded with an “edit\_beehive” action.  
Similarly, if I do this:

beehive.bees = bees # the line from above  
bees = beehive.bees

my bees have all been reverted to before I edited them.

I really don’t understand this. Some help would be appreciated.
