Persistence by reachability

Hello guys, I have these models

class Farmer < ActiveRecord::Base

 has_many :cows

end

class Cow < ActiveRecord::Base

set_table_name :cows
belongs_to :farmer

end

graph = Farmer.find(x) # Retrieves four cows of x

graph.cows[1].name = “Trottolina”

graph.save

while adding a new cow to collection works perfectly fine, ActiveRecord
doesn’t update for reachability the associated record why?

On Jan 16, 3:28pm, Vogon P. [email protected] wrote:

graph = Farmer.find(x) # Retrieves four cows of x

graph.cows[1].name = “Trottolina”

graph.save

while adding a new cow to collection works perfectly fine, ActiveRecord
doesn’t update for reachability the associated record why?

What do you mean by that?

Fred

Hey Vogon,

You should check out the autosave feature in ActiveRecord. I think this
is
what you’re looking for :slight_smile:

Cheers,
Richard

On Sun, Jan 16, 2011 at 11:08 AM, Frederick C. <

Richard Ramsden wrote in post #975325:

Hey Vogon,

You should check out the autosave feature in ActiveRecord. I think this
is
what you’re looking for :slight_smile:
ActiveRecord::AutosaveAssociation

Cheers,
Richard

On Sun, Jan 16, 2011 at 11:08 AM, Frederick C. <

Thanks Richard, I didn’t see your reply, YES AutosaveAssociation is what
I’m looking for!

Thanks for reply Frederick, What I wrote is really obscure, so let me
explain:

replacing the name ‘graph’ with farmer, imagine a situation where in
the
database there is a record that I retrieve with :

farmer = Farmer.find(2)

Well, this farmer has many cows associated, and these cows are loaded
on
the collection named ‘cows’, an Array with Cow objects; then suppose to
change the value of attribute ‘name’, of one of these objects of the
collection, perhaps the second cow:

farmer.cows[1].name = “another_name”

and then suppose to update all with :

farmer.save

In other ORM frameworks this results in updating the ‘dirty’ object of
the
collection but not in Active Record, why?