• Answers
  • Web
Personalize Yedda, (And make Danny Happy)
People ask & answer about almost everything. Tell us what you're interested in... So we can personalize Yedda especially for you
I'm interested in:

Detecting tranactions in Ruby on Rails

I have a Ruby on Rails question: 

I need a way to detect if the code is executing under a transaction.

So that I'll be able to enforce save only under transaction in some models. 


Share Send to a friend Watch Report
 
 

5 Posted Answers
Order by

 
8 helpful answers
Agile like Ninja 42squared

Pacman,

 

what form of transaction are you trying to detect?  Most items that will execute within a rails program can be monitored but the best bet would be to write test for the method/transaction so that you can create strick rules for what is going on.  I would like to know a little more about what it is that you are trying to do so that I can give a little more in depth answer. 

Posted 2006-09-09T15:47:39Z
hornbeck was invited by Yedda to answer this question.

 
4 helpful answers

What I'm trying to do is to make sure certain models are only ever saved inside a transaction.

So I wat to write a macro method such that I can do:

class Foo < ActiveRecrod::Base

  require_transaction

 end

And it will throw an exception if in before_save it detects that there's no transaction going. i.e.

@foo.save! # should fail

AnyOtherModelOrFoo.transaction do

  @foo.save! # should work

end

 

 Next stage will be detecting if the model is locked. i.e. if it was selected with :lock => true. But this is step 2 :-)

 

Posted 2006-09-09T16:32:11Z
 

It seems like there isn't really a built-in way to do this. I hear a lot about how RoR isn't strong on transactions. However, this looks like kind of a jury-rigged workaround:

if id.to_s =~ /transaction/ then
# inside a transaction
end

 I found this here.

Posted 2006-09-29T17:50:50Z
rholliday was invited by Yedda to answer this question.

 
4 helpful answers

That's not it. the code you linked is just a quick hack intended  to verify which transaction method gets called by setting a trace function and printing all the data on function calls when name contains word transaction and then running some ActiveRecord transaction code. The result: it's a class method


ActiveRecord::Transactions::ClassMethods#transaction
Posted 2006-09-30T00:11:27Z
 

Okay … I completely misread that code. Sorry about that.

Looking at the ActiveRecord transaction docs I wonder if you couldn't check to see that the thread had fired start_db_transaction, as it appears to do so when the transaction is started. However the Transaction::Simple module has a method transaction_open? that looks like it could verify a transaction was currently open, using named transactions.

I must admit I don't do much with RoR, so if the above doesn't help I hope hornbeck can provide some insight. :)

Posted 2006-09-30T02:10:07Z
rholliday was invited by Yedda to answer this question.

Sign in to participate

Got an answer for pacman? Would you like to comment on the posted answers, or vote for the one which you think is the best?

Sign up for a free account, or sign in (if you're already a member).

Explore Related Questions

Other people asked questions on similar topics, check out the answers they received:


Q:

Using Ruby on Rails to build large sites?

Can you build a site using Ruby on Rails that can handle the traffic levels of Myspace?
Submitted by sudonim   3 years ago.
  • viewed 3186 times
Last answer posted 2 years ago by Kuchmuch


Q:

Using Ruby for internal CRM app

I am about to start developing a new internal web application for the company I work for. It will be a lightweight CRM app ...
Submitted by Marti   3 years ago.
  • viewed 2358 times
Last answer posted 3 years ago by david_terrar


Q:

Rails Cascading Includes

Why can't I do cascading includes in ruby on rails: Tree.find(:first, :include => {:children => {:children => :children}}) I get ...
Submitted by richcollins   3 years ago.
  • viewed 472 times
Last answer posted 3 years ago by richcollins



» More...

Explore Related Posts in Forums

RForum -- Ruby on Rails Forum -- Help with Installation

And latest version Resolving Dependencies --> Running transaction check ---> Package ruby-docs.i386 ... Arch Version Repository Size Installing: ruby-docs i386 1.8.6.111-1 rubyworks 1.5 M Transaction I was looking to install RForum ( http://rforum.andreas-s.net/trac/ ) and I was wondering if anyone had any previous experience...

Simply Rails 2 [rake db:migrate] "rake aborted!"

Activerecord-2.2.2/lib/active_record/migration.rb:556:in `ddl_transaction' /usr/local/lib/ruby/gems/1.8/gems... Hi, I am a new user to RoR and very a very green programmer to boot. I am using the Simply Rails 2 . * If the database is already where you want it, why run the command again? * If it isn't, perhaps

looking for database structure help

Hello all, I am currently developing some prototypes for a heavy database web application from scalability issues from the database point of view, and I was wondering if anyone here had any . I am using ActiveRecord, since as of right now I am developing the application with Ruby on Rails
» More...
Powered by
Feed - Subscribe to changes to this Q&A Blog
ADVERTISEMENT
  • Answers
  • Web
Copyright © 2006-2009, Yedda Inc. and respective copyright owners · CC License