pedz
2007-Jul-14 23:50 UTC
before_save returning false does not roll back transaction -- save returns true
When a save of a record is going to cause more than one record to be saved because they have been associated with each other, if one of the records has a before_save callback which returns false, then that record is not saved (which is correct) but the records saved up to that point are not rolled back. e.g. foo = Foo.new bar = Bar.new foo.bars << bar foo.save If bar has a before_save call back that returns false, foo will get saved and the foo.save call will return true. Perhaps that is what should happen but I was expecting the whole transaction to get rolled back. I opened a bug report on this but it was closed. I need to supply a testcase. Thats fine... But I''d like first to know if this is bug or maybe a bug or definitely not a bug. Thank you for you time, Perry --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Pratik
2007-Jul-14 23:58 UTC
Re: before_save returning false does not roll back transaction -- save returns true
What happens when you try to raise an exception in before_save callback ? On 7/15/07, pedz <pedzsan@gmail.com> wrote:> > When a save of a record is going to cause more than one record to be > saved because they have been associated with each other, if one of the > records has a before_save callback which returns false, then that > record is not saved (which is correct) but the records saved up to > that point are not rolled back. > > e.g. > > foo = Foo.new > bar = Bar.new > foo.bars << bar > foo.save > > If bar has a before_save call back that returns false, foo will get > saved and the foo.save call will return true. > > Perhaps that is what should happen but I was expecting the whole > transaction to get rolled back. > > I opened a bug report on this but it was closed. I need to supply a > testcase. Thats fine... But I''d like first to know if this is bug or > maybe a bug or definitely not a bug. > > Thank you for you time, > Perry > > > > >-- http://m.onkey.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---