Need Explainantion of ActiveRecord::Base.transaction

Dear All:

Any one can help me to explain what is it for:

[1] ActiveRecord::Base.transaction and Customer.transaction ?

[2] What is deferences ActiveRecord::Base.transaction and Customer.transaction ?

[3] Is it the same like Transaction Support?

[4] Any one can give me proof of concept of ActiveRecord::Base.transaction ?

Thank you very much for your time and help.

Best Regards, Reinhart

Dear All:

Any one can help me to explain what is it for:

[1] ActiveRecord::Base.transaction and Customer.transaction ?

Most of the time they are identical. They're different if
Customer.connection != ActiveRecord::Base.connection

[2] What is deferences ActiveRecord::Base.transaction and Customer.transaction ?

No idea what you are talking about

[3] Is it the same like Transaction Support?

they are for database transactions

[4] Any one can give me proof of concept of ActiveRecord::Base.transaction ?

Customer.transaction do    #do something end

Fred

Thank You Fred,

I need to know :

[1] When do I use Model_name.transaction and When do I use ActiveRecord::Base.transaction?

[2] I have related tables in database and they are depended one each other. And they need having transaction support in a method. Which is good ActiveRecord::Base.transaction or each name_model.transaction ?

[3] Any good reference article that can explain it detail? I cant get it in google. Only sample code, but not explain process in transaction.

Once Again, Thank you very much.

Reinhart

Thank You Fred,

I need to know :

[1] When do I use Model_name.transaction and When do I use ActiveRecord::Base.transaction?

[2] I have related tables in database and they are depended one each other. And they need having transaction support in a method. Which is good ActiveRecord::Base.transaction or each name_model.transaction ?

Unless you're playing with multiple databases they're all the same

[3] Any good reference article that can explain it detail? I cant get it in google. Only sample code, but not explain process in transaction.

Don't know about that. there's not really an awful lot to say, it's just a means of running some code inside a database transaction. If an exception is thrown it's rolled back, if not it's committed (there's a specific exception you can throw to just roll back, can't remember the name but it will be in the docs.

Fred

Unless you do something specific to override the default functionality, a model that inherits from ActiveRecord::Base inherits the db connection that it uses. Indirectly, this means that ALL the models that inherit from ARec::Base will use the same connection (again, barring a specific override).

The transaction method, as Fred explains, provides an explicit way to mark the beginning and end of a db transaction. The transaction is run in the context of the db connection. If you have not done anything to override the way that your model sets/gets its DB connection then there is absolutely no difference between using transaction on ARec::Base or any of the models that inherited from it.