Forum: Ruby on Rails Contents of a has_many collection

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.
8a00145d61d84b58c4688cdc50bac48f?d=identicon&s=25 Wiebe Cazemier (halfgaar)
on 2007-06-06 17:51
(Received via mailing list)

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 =

params["bees"].each_value do |bee_attributes|
  bee =

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.
This topic is locked and can not be replied to.