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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 16, 3:28 pm, Vogon Primo <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hey Vogon, You should check out the autosave feature in ActiveRecord. I think this is what you''re looking for :) http://api.rubyonrails.org/classes/ActiveRecord/AutosaveAssociation.html Cheers, Richard On Sun, Jan 16, 2011 at 11:08 AM, Frederick Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Jan 16, 3:28 pm, Vogon Primo <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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 > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 :) > http://api.rubyonrails.org/classes/ActiveRecord/AutosaveAssociation.html > > Cheers, > Richard > > On Sun, Jan 16, 2011 at 11:08 AM, Frederick Cheung <Thanks Richard, I didn''t see your reply, YES AutosaveAssociation is what I''m looking for! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.