dino d.
2008-Jun-10 20:56 UTC
how to disable auto-save when adding new many records to an already saved master
Hi- I am having a bunch of problems with validates_associated when updating a record, and I think I have discovered the problem. If I have two models in a has_many relationship, if I use the << operator on a new master record, the slave records are not automatically saved until I call master.save. However, on an *existing* master record, the mere act of associated a new many record causes that many record to be saved. 1) What is the reasoning for this? 2) Can I disable it and have the many''s save only when I save the master? Thanks, Dino --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-10 21:42 UTC
Re: how to disable auto-save when adding new many records to an already saved master
On Jun 10, 9:56 pm, "dino d." <dinodorr...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Hi- > > I am having a bunch of problems with validates_associated when > updating a record, and I think I have discovered the problem. If I > have two models in a has_many relationship, if I use the << operator > on a new master record, the slave records are not automatically saved > until I call master.save. However, on an *existing* master record, > the mere act of associated a new many record causes that many record > to be saved. > > 1) What is the reasoning for this? > > 2) Can I disable it and have the many''s save only when I save the > master?Have a look at the Unsaved Associations section at http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
dino d.
2008-Jun-10 22:31 UTC
Re: how to disable auto-save when adding new many records to an already saved master
Thanks Fred -> Have a look at the Unsaved Associations section athttp://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMet... >Because I want to associate a mix of already saved, and new tags, what I wound up doing was for each tag, if it had an id (is there a saved? method?) I just associate it, otherwise, I build it, passing the tags attributes. This works, although I suspect there''s a better solution. What I''m trying to accomplish is to have a one-to-many on one form and I want to just push the errors for the many''s up to the one''s errors. So I added validates_associated, and it works fine on a new record. On an existing record, as soon as I associate the many record with the one, the many record saves, and if it''s invalid, it throws an exception, so the one record never even validates (so no error ever propagates to the one). Let me know if you have any thoughts on this. Thanks again, Dino --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---