http://edgeapi.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html under "Exception handling and rolling back" says that "*One should restart the entire transaction if an ActiveRecord::StatementInvalid occurred.*" My question is how? I tried wrapping the statements in two separate transaction block but that still doesn''t work. I have something like: self.transaction do bar = create!(params) rescue nil end unless bar self.transaction do bar = find_or_initialize_by(foo: foo) bar.update(params) end end and PG would still complain about it with "PG::Error: ERROR: current transaction is aborted, commands ignored until end of transaction block". So my question is whether there is a proper way of restarting the transaction? Thanks! Ken -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/7e361619-ecf2-4b61-b8ee-d3b588b16e0c%40googlegroups.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
On Jun 3, 2013, at 9:27 AM, Ken Ip wrote:> and PG would still complain about it with "PG::Error: ERROR: current transaction is aborted, commands ignored until end of transaction block". So my question is whether there is a proper way of restarting the transaction? Thanks!rollback -- Scott Ribe scott_ribe-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org http://www.elevated-dev.com/ (303) 722-0567 voice -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1D1B97E2-773E-46DF-B302-3BD63B362769%40elevated-dev.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Thanks for the reply, Scott. Can you show me how? I''ve tried per this<http://api.rubyonrails.org/classes/ActiveRecord/Rollback.html> but it still doesn''t work. self.transaction do bar = create(params) rescue nil raise ActiveRecord::Rollback unless bar end unless bar self.transaction do bar = find_or_initialize_by(foo: foo) bar.update(params) end end On Monday, June 3, 2013 11:57:21 AM UTC-4, Scott Ribe wrote:> > On Jun 3, 2013, at 9:27 AM, Ken Ip wrote: > > > and PG would still complain about it with "PG::Error: ERROR: current > transaction is aborted, commands ignored until end of transaction block". > So my question is whether there is a proper way of restarting the > transaction? Thanks! > > rollback > > -- > Scott Ribe > scott...-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org <javascript:> > http://www.elevated-dev.com/ > (303) 722-0567 voice > > > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/df6adad0-6740-400a-8771-f034d54452fe%40googlegroups.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Look at the actual SQL in the logs. On Jun 3, 2013, at 9:01 PM, Ken Ip wrote:> Thanks for the reply, Scott. Can you show me how? I''ve tried per this but it still doesn''t work. > > > self.transaction do > bar = create(params) rescue nil > raise ActiveRecord::Rollback unless bar > end > unless bar > self.transaction do > bar = find_or_initialize_by(foo: foo) > bar.update(params) > end > end > > > On Monday, June 3, 2013 11:57:21 AM UTC-4, Scott Ribe wrote: > On Jun 3, 2013, at 9:27 AM, Ken Ip wrote: > > > and PG would still complain about it with "PG::Error: ERROR: current transaction is aborted, commands ignored until end of transaction block". So my question is whether there is a proper way of restarting the transaction? Thanks! > > rollback > > -- > Scott Ribe > scott...-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org > http://www.elevated-dev.com/ > (303) 722-0567 voice > > > > > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/df6adad0-6740-400a-8771-f034d54452fe%40googlegroups.com?hl=en-US. > For more options, visit https://groups.google.com/groups/opt_out. > >-- Scott Ribe scott_ribe-ZCQMRMivIIdUL8GK/JU1Wg@public.gmane.org http://www.elevated-dev.com/ (303) 722-0567 voice -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/E01BEA3F-7C43-4A31-B40E-D1E5CD894D39%40elevated-dev.com. For more options, visit https://groups.google.com/groups/opt_out.