is it possible to / how can you check if you are currently within a transaction? I''d like a method to raise an error if it is called from outside of a transaction, but run normally otherwise. Checking the transaction documentation: http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html I don''t see a way to accomplish this...? -- 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 19 Mar 2011, at 19:30, GS <gabe.saravia-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> is it possible to / how can you check if you are currently within a > transaction?You could check connection.open_transactions On postgres you can ask the adapter directly if my memory is correct Fred> > I''d like a method to raise an error if it is called from outside of a > transaction, but run normally otherwise. > > Checking the transaction documentation: > > http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html > > I don''t see a way to accomplish this...? > > -- > 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. >-- 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 Saturday 19 March 2011, GS wrote:> is it possible to / how can you check if you are currently within a > transaction? > > I''d like a method to raise an error if it is called from outside of a > transaction, but run normally otherwise.You could just wrap the code in your method in a transaction block. As the docs say: +transaction+ calls can be nested. By default, this makes all database statements in the nested transaction block become part of the parent transaction. I.e., a nested transaction block does *not* result in a nested transaction. If you want the latter, you have to use transaction(:requires_new => true). Michael -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ -- 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.