How does the save method work with has_many? Code Details

Hi,

I’m trying to fix a plugin that is adding the equivalent of a has_many
relationship to an object. Here is what I understand has_many does and
how it mixins in with the concrete object. If I have an object Foo and
it has_many Bars then here is the code:

class Foo < ActiveRecord::Base
has_many :bars
end

What that does is add several methods to manage that relationship, and
it stores an array under the @bars instance variable that stores the
individual instances of Bar. Now regular fields from the database are
stored in @attributes instance variable. What I’m a little fuzzy on is
how does save know to commit both attributes and the @bars instance
variable when the user calls save method?

Effectively I’m trying to modify a plugin so that it will cache this
collection similiar to has_many, and it will commit that collection when
you save. Right now it is always commiting and always reading from the
datbase and stores nothing in memory.

Charlie