Wes Gamble
2007-Jan-19 21:25 UTC
Do transactions fail with polymorphic has_one relationships?
I have an AR::Base descendant with a complex object graph beneath it, like so: ArtisanQuoteInput has_one QuoteInput and then QuoteInput has several objects attached to it. Note that the relationship between ArtisanQuoteInput and QuoteInput is polymorphic, so the relationship in A is written has_one :quote_input, :as => :program_quote_input If @artisan_quote_input is an instance of ArtisanQuoteInput and I call @artisan_quote_input.save!, and just one of its attributes is invalid (meaning that @artisan_quote_input fails validation), what I see is that the quote_input object and all of its children save to the database successfully. Supposedly, according to AWDWR, 2nd. ed. (p. 386), there should be an implicit transaction around the @a.save! call. But I''m not seeing this. I''d expect that none of the child data would be saved. So I put an explicit transaction around this call, like so: ArtisanQuoteInput.connection.transaction do @artisan_quote_input.save! end The same behavior occurs, e.g. an incomplete rollback. The only thing that seems out of the ordinary is the polymorphic relationship between ArtisanQuoteInput and QuoteInput, but frankly, I don''t really see why that should matter. So am I misunderstanding the workings of the transaction method in Rails or is there something about polymorphic is_one relationships that makes transactions not work correctly? Thanks, Wes -- 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-/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 -~----------~----~----~----~------~----~------~--~---