-
Notifications
You must be signed in to change notification settings - Fork 37
Conversation
Hi @leandrogehlen , Thank you (again) for your pull request. Thoughts? |
The user, can decide even with this implementation, the only thing changed is, when user use the SaveRelationsTrait, the default behavior will be start a transaction
I thought about it too, but adding property or rewrite the method, i think is the same work. |
But if you think better, to create property, to keep backward compatibility, it's simple implementation. |
Indeed. I would prefer to add an |
Sorry to bother you but in my opinion, the trait method should not be mandatory. I think that we should rather modify the |
Sorry, i did not pay attention about this methods. But really don't think this methods are necessary, because ActveReccord handle this behavior. |
The start transaction mechanism is there for a purpose: some newly created has one relations need to be saved prior to the main model in order to be correctly validated and linked. If you remove the transaction, you could end up with unwanted orphan records. |
I understand, but applications with big number of records, and a big request number, to execute |
I'm opened to suggestions ;)
|
My suggestion is
The links bellow has some issues with transactions https://www.simononsoftware.com/are-long-running-transactions-bad/
I'm using mysql/postgres but the transaction issue is common for any DBMS |
Thank you for the answers. Moving start transaction to |
You don't need to control transactions if you to use and transactions will be started before by https://github.com/yiisoft/yii2/blob/master/framework/db/ActiveRecord.php#L628 Thinking about it, i found another issue: $modelWithRelation->save(false); In this case, the |
Hi @leandrogehlen, |
@leandrogehlen I've just pushed a quick fix. Let me know. |
i don't have deep knowledge about your code. I think a little strange to save If is really necessary this feature, i don't see a solution. Request 1
Request 2
|
Well, I guess you’re right about the fact that it’s kind of a edge scenario. But not impossible. I agree the transition can lead to issues too for validation purposes. |
I think a crital issue, and if you have big an application with many request, this situation happens frequently |
Hi @leandrogehlen, |
I guess, it was a great solution, and it solve both situations. |
I will close that one as the initial purpose is kind of out of scope. |
Avoid rewrite
transactions
method usingSaveRelationsTrait