Thursday, January 26, 2012

Re: using transactions in cake

If you are able to wrap all the saves into on saveAll, that would work. Otherwise, another thing I've done is validation everything first, then save if everything passes. This obviously won't catch for not actually being able to save in the database, but if your validation is spot on it shouldn't be too much of a problem.

Lastly, if you look at the code behind saveAll you'll see the necessary methods to run transactions on the datasource level, i.e., manually setting the data, validation, beginning, committing and maybe rolling back the transaction. It might be a lot more work to do it this way.

Thoughts on improving this are welcome. Add an RFC ticket to lighthouse with a use case and a patch (with tests), and see what people think!

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: