Support Transaction operation on DB - Mysql #1004

Closed
hellomaya opened this Issue Aug 28, 2013 · 5 comments

Projects

None yet

4 participants

@hellomaya

I didn't find it in Lithium yet. I think It's necessary, while I was working on e-commerce website in Lithium. As PHP PDO library support Transaction Operation (http://php.net/manual/en/pdo.begintransaction.php), and Mysql InnoDB engine support it too.

@gianbasagre

I believe you can just get the PDO object and start the transaction. Something like:

$foo = app\models\Foo::create();
$pdo = Connections::get('default')->connection; // Returns the PDO object
$pdo->beginTransaction();
$foo->bar = 'Hello';
$foo->save();
$pdo->commit();
@hellomaya

Thank you, that's what I am looking for. But I still think Lithium should support it directly, since it's critical for e-commerce db transaction.

@gianbasagre

I'm not entirely sure but maybe it's designed that way to make models datasource agnostic? Since models can use MongoDB, REST, etc.

A clean solution is to create a base class for models using MySQL and add a method for transactions.

@gwoo
Member
gwoo commented Sep 5, 2013

or use filters.

On Sep 4, 2013, at 11:43 PM, Gian Basagre notifications@github.com wrote:

I'm not entirely sure but maybe it's designed that way to make models datasource agnostic? Since models can use MongoDB, REST, etc.

A clean solution is to create a base class for models using MySQL and add a method for transactions.


Reply to this email directly or view it on GitHub.

@davidpersson
Member

Connections::get('default')->connection->beginTransaction() is currently the way to go. I agree with you, @hellomaya for certain types of applications it is critical to have them. I'm personally keeping a static pdo() method in my base model class. So that I can quickly access it like so Posts::pdo()->beginTransaction().

@gianbasagre is right, models are data source agnostic. Transactions cannot be abstracted are details of the underlying data sources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment